@alipay/ams-checkout 2.0.2 → 2.0.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.
@@ -8,10 +8,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
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
10
  import { EnvironmentEnum } from "../../../types";
11
- import { LogComplianceProcessor } from "./processor";
12
11
  import { isPC } from "../../../util";
13
- import { getStorageString, setStorageString } from "../../../util/storage";
14
12
  import { SPM_MAP } from "../../../util/spm-map";
13
+ import { getStorageString, setStorageString } from "../../../util/storage";
14
+ import { LogComplianceProcessor } from "./processor";
15
15
 
16
16
  /**
17
17
  * @author 谦彧 <zhangmian.zm@alipay.com>
@@ -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;
@@ -190,21 +227,26 @@ export var LogService = /*#__PURE__*/function () {
190
227
  script.onerror = function () {
191
228
  console.error("unable to load Antom script: ".concat(url));
192
229
  };
193
- document.body.appendChild(script);
230
+ // CDN 方式接入 sdk,执行时机可能在 body 创建之前
231
+ if (document.body) {
232
+ document.body.appendChild(script);
233
+ } else if (document.head) {
234
+ document.head.appendChild(script);
235
+ }
194
236
  }
195
237
  }, {
196
238
  key: "initTracker",
197
239
  value: function initTracker() {
198
- var _this3 = this;
240
+ var _this4 = this;
199
241
  if (this.isLoaded) return;
200
242
  this.isLoaded = true;
201
243
  try {
202
244
  if (typeof localStorage !== 'undefined') {
203
245
  this.loadScript(this.config.scriptUrl, function () {
204
246
  var _window4;
205
- (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this3.config);
247
+ (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this4.config);
206
248
  setTimeout(function () {
207
- _this3.reportLogs();
249
+ _this4.reportLogs();
208
250
  }, 80);
209
251
  });
210
252
  }
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
  }, {
@@ -193,7 +193,9 @@ export var ApplePaySdk = /*#__PURE__*/function () {
193
193
  _context2.prev = 0;
194
194
  requestParams = {
195
195
  validateUrl: event === null || event === void 0 ? void 0 : event.validationURL,
196
- paymentSessionData: _this.paymentSessionData
196
+ paymentSessionData: _this.paymentSessionData,
197
+ // TODO: 新增appplay入参
198
+ merchantDomain: window.location.hostname
197
199
  };
198
200
  _context2.t0 = getApplePayPaymentSession;
199
201
  _context2.t1 = _this.paymentSessionData;
@@ -395,7 +397,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
395
397
  key: "initApplePaySession",
396
398
  value: function () {
397
399
  var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
398
- var _this$logger7, _this$parseData3, _this$logger6, _this$parseData$payme2, recurringInfo, version, _this$logger8;
400
+ var _this$logger7, _this$parseData3, _this$logger6, _ref4, recurringInfo, version, _this$logger8;
399
401
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
400
402
  while (1) switch (_context5.prev = _context5.next) {
401
403
  case 0:
@@ -430,7 +432,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
430
432
  }
431
433
  throw new Error('Apple Pay not supported');
432
434
  case 12:
433
- _this$parseData$payme2 = (_this$parseData3 = this.parseData) === null || _this$parseData3 === void 0 ? void 0 : _this$parseData3.paymentSessionFactor, recurringInfo = _this$parseData$payme2.recurringInfo;
435
+ _ref4 = ((_this$parseData3 = this.parseData) === null || _this$parseData3 === void 0 ? void 0 : _this$parseData3.paymentSessionFactor) || {}, recurringInfo = _ref4.recurringInfo;
434
436
  version = recurringInfo ? APPLE_PAY_RECURRING_VERSION : APPLE_PAY_VERSION;
435
437
  if (this.isCanMakePayments(version)) {
436
438
  _context5.next = 16;
@@ -478,12 +480,12 @@ export var ApplePaySdk = /*#__PURE__*/function () {
478
480
  key: "initSessionParams",
479
481
  get: function get() {
480
482
  var _this$parseData4;
481
- var _ref4 = ((_this$parseData4 = this.parseData) === null || _this$parseData4 === void 0 ? void 0 : _this$parseData4.paymentSessionFactor) || {},
482
- merchantInfo = _ref4.merchantInfo,
483
- order = _ref4.order,
484
- paymentAmount = _ref4.paymentAmount,
485
- recurringInfo = _ref4.recurringInfo,
486
- extendInfo = _ref4.extendInfo;
483
+ var _ref5 = ((_this$parseData4 = this.parseData) === null || _this$parseData4 === void 0 ? void 0 : _this$parseData4.paymentSessionFactor) || {},
484
+ merchantInfo = _ref5.merchantInfo,
485
+ order = _ref5.order,
486
+ paymentAmount = _ref5.paymentAmount,
487
+ recurringInfo = _ref5.recurringInfo,
488
+ extendInfo = _ref5.extendInfo;
487
489
  var request = {
488
490
  countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
489
491
  currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
@@ -529,10 +531,10 @@ export var ApplePaySdk = /*#__PURE__*/function () {
529
531
  key: "isRequiredParameters",
530
532
  get: function get() {
531
533
  var _this$parseData5;
532
- var _ref5 = ((_this$parseData5 = this.parseData) === null || _this$parseData5 === void 0 ? void 0 : _this$parseData5.paymentSessionFactor) || {},
533
- merchantInfo = _ref5.merchantInfo,
534
- extendInfo = _ref5.extendInfo,
535
- paymentAmount = _ref5.paymentAmount;
534
+ var _ref6 = ((_this$parseData5 = this.parseData) === null || _this$parseData5 === void 0 ? void 0 : _this$parseData5.paymentSessionFactor) || {},
535
+ merchantInfo = _ref6.merchantInfo,
536
+ extendInfo = _ref6.extendInfo,
537
+ paymentAmount = _ref6.paymentAmount;
536
538
  return !isEmpty(merchantInfo) && !isEmpty(paymentAmount) && !isEmpty(extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks) && !isEmpty(extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities);
537
539
  }
538
540
  }, {
@@ -620,6 +620,7 @@ export interface CashierSdkActionQuerySessionResult extends IPaymentSessionMetaD
620
620
  export interface ApplePayPaymentSessionRequest {
621
621
  validateUrl: string;
622
622
  paymentSessionData: string;
623
+ merchantDomain?: string;
623
624
  }
624
625
  /**
625
626
  * Get App Pay Payment Session Result.
@@ -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;
@@ -183,21 +220,26 @@ export var Logger = /*#__PURE__*/function () {
183
220
  script.onerror = function () {
184
221
  console.error("unable to load Antom script: ".concat(url));
185
222
  };
186
- document.body.appendChild(script);
223
+ // CDN 方式接入 sdk,执行时机可能在 body 创建之前
224
+ if (document.body) {
225
+ document.body.appendChild(script);
226
+ } else if (document.head) {
227
+ document.head.appendChild(script);
228
+ }
187
229
  }
188
230
  }, {
189
231
  key: "initTracker",
190
232
  value: function initTracker() {
191
- var _this5 = this;
233
+ var _this6 = this;
192
234
  if (this.isLoaded) return;
193
235
  this.isLoaded = true;
194
236
  try {
195
237
  if (typeof localStorage !== 'undefined') {
196
238
  this.loadScript(this.config.scriptUrl, function () {
197
239
  var _window4;
198
- (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this5.config);
240
+ (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this6.config);
199
241
  setTimeout(function () {
200
- _this5.reportLogs();
242
+ _this6.reportLogs();
201
243
  }, 80);
202
244
  });
203
245
  }
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.5",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",