@alipay/ams-checkout 1.9.0 → 1.10.1

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.
@@ -22,7 +22,7 @@ import { queryPaymentInfo, submitPayInfo } from "../../service";
22
22
  import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, RedirectType, renderDisplayTypeEnum, targetEnum } from "../../types";
23
23
  import { getType, isJsonString, isPC } from "../../util";
24
24
  import { isLocalMock } from "../../util/mock";
25
- import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
25
+ import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
26
26
  import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
27
27
  import { addPopupLoading, createBaseElement, createMockup, createRetentionPopup, handleDeclareInfo as _handleDeclareInfo, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup } from "./component.popup.style";
28
28
  import { createModal, destroyModal, insertStyleSheet } from "./popupWindow.style";
@@ -40,6 +40,7 @@ var ComponentApp = /*#__PURE__*/function () {
40
40
  _defineProperty(this, "popupApp", void 0);
41
41
  _defineProperty(this, "appDomain", void 0);
42
42
  _defineProperty(this, "createIframeNode", void 0);
43
+ _defineProperty(this, "createPreloadIframeNode", void 0);
43
44
  _defineProperty(this, "_selector", void 0);
44
45
  _defineProperty(this, "_appVersion", void 0);
45
46
  _defineProperty(this, "_isRetention", void 0);
@@ -53,12 +54,15 @@ var ComponentApp = /*#__PURE__*/function () {
53
54
  _defineProperty(this, "_merchantAppointParam", void 0);
54
55
  _defineProperty(this, "_webAppHeartBeatTimeoutId", void 0);
55
56
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
56
- this._appVersion = '1.9.0';
57
+ this._appVersion = '1.10.1';
57
58
  this._isInitComponent = false;
58
59
  this._selector = "#".concat(COMPONENT_SECTION_ID);
59
60
  this.createIframeNode = function () {
60
61
  return Promise.resolve();
61
62
  };
63
+ this.createPreloadIframeNode = function () {
64
+ return Promise.resolve();
65
+ };
62
66
  this.platform = isPC() ? platformEnum.desktop : platformEnum.mobile;
63
67
  this._isRetention = true;
64
68
  this._appLocationSearch = '';
@@ -119,6 +123,11 @@ var ComponentApp = /*#__PURE__*/function () {
119
123
  value: function setRender(renderFunc) {
120
124
  this.createIframeNode = renderFunc;
121
125
  }
126
+ }, {
127
+ key: "setPreloadRender",
128
+ value: function setPreloadRender(renderFunc) {
129
+ this.createPreloadIframeNode = renderFunc;
130
+ }
122
131
  }, {
123
132
  key: "initSecurity",
124
133
  value: function initSecurity() {
@@ -280,6 +289,18 @@ var ComponentApp = /*#__PURE__*/function () {
280
289
  return Promise.reject(error);
281
290
  });
282
291
  }
292
+ }, {
293
+ key: "appendPreloadIframeNodes",
294
+ value: function appendPreloadIframeNodes(componentSign, productSceneVersion) {
295
+ var virtualPreloadIframe = this.createPreloadApp(componentSign, productSceneVersion);
296
+ this.createPreloadIframeNode(virtualPreloadIframe);
297
+ this.AMSSDK.logger.logInfo({
298
+ title: 'performance_optimization_preload'
299
+ }, {
300
+ componentSign: componentSign,
301
+ productSceneVersion: productSceneVersion
302
+ });
303
+ }
283
304
  }, {
284
305
  key: "setParameterDefaultValues",
285
306
  value: function setParameterDefaultValues(componentSign, renderParams) {
@@ -342,8 +363,8 @@ var ComponentApp = /*#__PURE__*/function () {
342
363
  // eslint-disable-next-line no-async-promise-executor
343
364
  this._actionQueryPromise = new Promise( /*#__PURE__*/function () {
344
365
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
345
- var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4;
346
- var envInfo, params, _this5$_renderParams5, _ref3, _ref3$productSceneVer, productSceneVersion, _ref3$productScene, productScene, _ref4, _ref4$action, _ref4$action2, _ref4$action2$autoDeb, autoDebitWithToken, _this5$_renderParams6, _action$web, _action$wap, action, signType;
366
+ var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4, _this5$_renderParams5;
367
+ var envInfo, params, _this5$_renderParams$, extendInfo, enableVaultingApiOptimize, enableEasypayApiOptimize, extendInfoData, _this5$_renderParams6, _this5$_renderParams7, _ref3, _ref3$productSceneVer, productSceneVersion, _ref3$productScene, productScene, _ref4, _ref4$action, _ref4$action2, _ref4$action2$autoDeb, autoDebitWithToken, _this5$_renderParams8, _action$web, _action$wap, action, signType;
347
368
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
348
369
  while (1) switch (_context2.prev = _context2.next) {
349
370
  case 0:
@@ -359,78 +380,106 @@ var ComponentApp = /*#__PURE__*/function () {
359
380
  /**
360
381
  * @description Simulated or unnecessary scenarios
361
382
  */
362
- if (!(isLocalMock() || (_this5$_renderParams4 = _this5._renderParams) !== null && _this5$_renderParams4 !== void 0 && (_this5$_renderParams4 = _this5$_renderParams4.paymentSessionMetaData) !== null && _this5$_renderParams4 !== void 0 && (_this5$_renderParams4 = _this5$_renderParams4.action) !== null && _this5$_renderParams4 !== void 0 && _this5$_renderParams4.skipSdkQuery)) {
363
- _context2.next = 4;
383
+ _this5$_renderParams$ = (_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData, extendInfo = _this5$_renderParams$.extendInfo;
384
+ enableVaultingApiOptimize = false;
385
+ enableEasypayApiOptimize = false;
386
+ try {
387
+ extendInfoData = JSON.parse(extendInfo);
388
+ enableVaultingApiOptimize = extendInfoData.enableVaultingApiOptimize || false;
389
+ enableEasypayApiOptimize = extendInfoData.enableEasypayApiOptimize || false;
390
+ } catch (error) {
391
+ console.log(error);
392
+ }
393
+ if (!isLocalMock()) {
394
+ _context2.next = 8;
364
395
  break;
365
396
  }
366
397
  return _context2.abrupt("return", resolve({
367
398
  message: 'sdk no need to make query request',
368
399
  success: true
369
400
  }));
370
- case 4:
371
- if (!(componentSignEnum.CASHIER_PAYMENT_CARD === _this5._componentSign || componentSignEnum.VAULTING_CARD === _this5._componentSign)) {
401
+ case 8:
402
+ if (!(componentSignEnum.VAULTING_CARD === _this5._componentSign && (_this5$_renderParams5 = _this5._renderParams) !== null && _this5$_renderParams5 !== void 0 && (_this5$_renderParams5 = _this5$_renderParams5.paymentSessionMetaData) !== null && _this5$_renderParams5 !== void 0 && (_this5$_renderParams5 = _this5$_renderParams5.action) !== null && _this5$_renderParams5 !== void 0 && _this5$_renderParams5.skipSdkQuery && enableVaultingApiOptimize)) {
372
403
  _context2.next = 10;
373
404
  break;
374
405
  }
406
+ return _context2.abrupt("return", resolve({
407
+ message: 'sdk no need to make query request',
408
+ success: true
409
+ }));
410
+ case 10:
411
+ if (!(componentSignEnum.CASHIER_PAYMENT_CARD === _this5._componentSign || componentSignEnum.VAULTING_CARD === _this5._componentSign)) {
412
+ _context2.next = 16;
413
+ break;
414
+ }
375
415
  params.paymentMethodType = 'CARD';
376
- _context2.next = 8;
416
+ _context2.next = 14;
377
417
  return _this5.getDeviceIdAndLog();
378
- case 8:
418
+ case 14:
379
419
  envInfo.deviceId = _context2.sent;
380
420
  if (window.navigator.userAgent.indexOf('miniProgram') > -1) {
381
421
  envInfo.extendInfo = {
382
422
  WAP_SUB_TYPE: 'WECHAT_MINI_PROGRAM'
383
423
  };
384
424
  }
385
- case 10:
425
+ case 16:
386
426
  if (!(componentSignEnum.EASY_PAY_WALLET === _this5._componentSign)) {
387
- _context2.next = 18;
427
+ _context2.next = 26;
388
428
  break;
389
429
  }
390
430
  _ref3 = params.paymentSessionConfig || {}, _ref3$productSceneVer = _ref3.productSceneVersion, productSceneVersion = _ref3$productSceneVer === void 0 ? '' : _ref3$productSceneVer, _ref3$productScene = _ref3.productScene, productScene = _ref3$productScene === void 0 ? '' : _ref3$productScene;
391
- _ref4 = ((_this5$_renderParams5 = _this5._renderParams) === null || _this5$_renderParams5 === void 0 ? void 0 : _this5$_renderParams5.paymentSessionMetaData) || {}, _ref4$action = _ref4.action, _ref4$action2 = _ref4$action === void 0 ? {} : _ref4$action, _ref4$action2$autoDeb = _ref4$action2.autoDebitWithToken, autoDebitWithToken = _ref4$action2$autoDeb === void 0 ? false : _ref4$action2$autoDeb;
431
+ _ref4 = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.paymentSessionMetaData) || {}, _ref4$action = _ref4.action, _ref4$action2 = _ref4$action === void 0 ? {} : _ref4$action, _ref4$action2$autoDeb = _ref4$action2.autoDebitWithToken, autoDebitWithToken = _ref4$action2$autoDeb === void 0 ? false : _ref4$action2$autoDeb;
432
+ if (!((_this5$_renderParams7 = _this5._renderParams) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.paymentSessionMetaData) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.action) !== null && _this5$_renderParams7 !== void 0 && _this5$_renderParams7.skipSdkQuery && enableEasypayApiOptimize)) {
433
+ _context2.next = 21;
434
+ break;
435
+ }
436
+ return _context2.abrupt("return", resolve({
437
+ message: 'sdk no need to make query request',
438
+ success: true
439
+ }));
440
+ case 21:
392
441
  if (!(productScene === productSceneEnum.EASY_PAY && productSceneVersion === '2.0' && !autoDebitWithToken)) {
393
- _context2.next = 15;
442
+ _context2.next = 23;
394
443
  break;
395
444
  }
396
445
  return _context2.abrupt("return", resolve({
397
446
  message: 'sdk no need to make query request',
398
447
  success: true
399
448
  }));
400
- case 15:
401
- _context2.next = 17;
449
+ case 23:
450
+ _context2.next = 25;
402
451
  return _this5.getDeviceIdAndLog();
403
- case 17:
452
+ case 25:
404
453
  envInfo.deviceId = _context2.sent;
405
- case 18:
454
+ case 26:
406
455
  if (!(componentSignEnum.AUTO_DEBIT_WALLET === _this5._componentSign)) {
407
- _context2.next = 28;
456
+ _context2.next = 36;
408
457
  break;
409
458
  }
410
- action = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 || (_this5$_renderParams6 = _this5$_renderParams6.paymentSessionMetaData) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.action) || {};
459
+ action = ((_this5$_renderParams8 = _this5._renderParams) === null || _this5$_renderParams8 === void 0 || (_this5$_renderParams8 = _this5$_renderParams8.paymentSessionMetaData) === null || _this5$_renderParams8 === void 0 ? void 0 : _this5$_renderParams8.action) || {};
411
460
  signType = isPC() ? action === null || action === void 0 || (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 || (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType;
412
461
  if (!(signType === 'SMS')) {
413
- _context2.next = 23;
462
+ _context2.next = 31;
414
463
  break;
415
464
  }
416
465
  return _context2.abrupt("return", resolve({
417
466
  message: 'sdk no need to make query request',
418
467
  success: true
419
468
  }));
420
- case 23:
469
+ case 31:
421
470
  if (!(!signType || signType !== 'REDIRECT')) {
422
- _context2.next = 25;
471
+ _context2.next = 33;
423
472
  break;
424
473
  }
425
474
  return _context2.abrupt("return", resolve({
426
475
  success: false
427
476
  }));
428
- case 25:
429
- _context2.next = 27;
477
+ case 33:
478
+ _context2.next = 35;
430
479
  return _this5.getDeviceIdAndLog();
431
- case 27:
480
+ case 35:
432
481
  envInfo.deviceId = _context2.sent;
433
- case 28:
482
+ case 36:
434
483
  _this5.AMSSDK.logger.logInfo({
435
484
  title: 'sdk_event_sdkQuery'
436
485
  }, {
@@ -444,11 +493,7 @@ var ComponentApp = /*#__PURE__*/function () {
444
493
  key: 'sdk_action_query_end',
445
494
  value: Date.now()
446
495
  });
447
- if (res !== null && res !== void 0 && res.success) {
448
- resolve(res);
449
- } else {
450
- resolve(res);
451
- }
496
+ resolve(res);
452
497
  }).catch(function (err) {
453
498
  if ([componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.VAULTING_CARD, componentSignEnum.CASHIER_PAYMENT_APM].includes(_this5._componentSign)) {
454
499
  return resolve({
@@ -466,7 +511,7 @@ var ComponentApp = /*#__PURE__*/function () {
466
511
  paymentSessionConfig: JSON.stringify(params.paymentSessionConfig)
467
512
  }).send();
468
513
  });
469
- case 30:
514
+ case 38:
470
515
  case "end":
471
516
  return _context2.stop();
472
517
  }
@@ -478,6 +523,8 @@ var ComponentApp = /*#__PURE__*/function () {
478
523
  }());
479
524
  return this._actionQueryPromise;
480
525
  }
526
+
527
+ // private create
481
528
  }, {
482
529
  key: "createSubmitPromise",
483
530
  value: function createSubmitPromise() {
@@ -593,7 +640,40 @@ var ComponentApp = /*#__PURE__*/function () {
593
640
  console.error(error);
594
641
  }
595
642
  }
596
-
643
+ // 预加载iframe创建
644
+ }, {
645
+ key: "createPreloadApp",
646
+ value: function createPreloadApp(componentSign) {
647
+ var productSceneVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.0';
648
+ var preloadIframe = createPreloadIframe(componentSign, productSceneVersion);
649
+ var _getIframeUrl = getIframeUrl({
650
+ renderDisplayType: renderDisplayTypeEnum.popup,
651
+ componentSign: componentSign,
652
+ analytics: {
653
+ enabled: false
654
+ },
655
+ productSceneVersion: productSceneVersion,
656
+ environment: this.AMSSDK.options.env.environment,
657
+ // TODO 确定一下这个参数是干啥的
658
+ appVersion: this._appVersion,
659
+ extendInfo: '',
660
+ locale: '',
661
+ instanceId: '',
662
+ isPreload: 'true'
663
+ }),
664
+ path = _getIframeUrl.path,
665
+ locationSearch = _getIframeUrl.locationSearch;
666
+ preloadIframe.src = "".concat(path, "?").concat(locationSearch);
667
+ if (!path) {
668
+ this.AMSSDK.logger.logError({
669
+ title: 'performance_optimization_preload_path_error'
670
+ }, {
671
+ path: path,
672
+ locationSearch: locationSearch
673
+ });
674
+ }
675
+ return preloadIframe;
676
+ }
597
677
  /**
598
678
  * @description Create app
599
679
  */
@@ -621,7 +701,8 @@ var ComponentApp = /*#__PURE__*/function () {
621
701
  extendInfo: extendInfo
622
702
  });
623
703
  this.app = createIframe(this.AMSSDK.options.mode, this.platform);
624
- var _getIframeUrl = getIframeUrl({
704
+ var hostSign = ((renderParams === null || renderParams === void 0 ? void 0 : renderParams.sessionData) || '').split('&&')[1] || '';
705
+ var _getIframeUrl2 = getIframeUrl({
625
706
  renderDisplayType: renderParams.renderDisplayType,
626
707
  componentSign: this._componentSign,
627
708
  analytics: this.AMSSDK.options.analytics,
@@ -630,10 +711,11 @@ var ComponentApp = /*#__PURE__*/function () {
630
711
  appVersion: this._appVersion,
631
712
  extendInfo: extendInfo,
632
713
  locale: this.AMSSDK.options.locale,
633
- instanceId: this.AMSSDK._instanceId
714
+ instanceId: this.AMSSDK._instanceId,
715
+ hostSign: hostSign
634
716
  }),
635
- path = _getIframeUrl.path,
636
- locationSearch = _getIframeUrl.locationSearch;
717
+ path = _getIframeUrl2.path,
718
+ locationSearch = _getIframeUrl2.locationSearch;
637
719
  this._appLocationSearch = locationSearch;
638
720
  this.app.src = "".concat(path, "?").concat(locationSearch);
639
721
 
@@ -153,6 +153,9 @@ export interface IpaymentSessionMetaData {
153
153
  paymentMethodInfo?: {
154
154
  paymentMethodType?: string;
155
155
  };
156
+ paymentMethodViewMetaData?: any;
157
+ paymentRequestId?: string;
158
+ supportedLanguages?: any;
156
159
  };
157
160
  }
158
161
  export declare enum localeEnum {
@@ -3,3 +3,4 @@ import { Iselector, renderDisplayTypeEnum } from '../types';
3
3
  * @description context中需要包含app节点,用于插入selector中
4
4
  */
5
5
  export declare const createIframeNode: (context: any, selector: Iselector, renderDisplayType: renderDisplayTypeEnum) => Promise<void>;
6
+ export declare const createPreloadIframeNode: (virtualPreloadIframe: any) => void;
@@ -39,4 +39,10 @@ export var createIframeNode = function createIframeNode(context, selector, rende
39
39
  }
40
40
  resolve();
41
41
  });
42
+ };
43
+ export var createPreloadIframeNode = function createPreloadIframeNode(virtualPreloadIframe) {
44
+ var body = document.body || null;
45
+ if (body) {
46
+ body.appendChild(virtualPreloadIframe);
47
+ }
42
48
  };
@@ -37,4 +37,5 @@ declare const addSetFontSizeEvent: () => void;
37
37
  */
38
38
  declare const getOrSetStorageId: (key: string, value?: string) => string;
39
39
  declare const checkTimeElapsed: () => boolean;
40
- export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed, };
40
+ declare function parseBase64ToString(base64: string): string;
41
+ export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed, parseBase64ToString, };
package/esm/util/index.js CHANGED
@@ -246,4 +246,17 @@ var checkTimeElapsed = function checkTimeElapsed() {
246
246
  localStorage.setItem(key, currentTime.toString());
247
247
  return true;
248
248
  };
249
- export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed };
249
+
250
+ // https://developer.mozilla.org/en-US/docs/Glossary/Base64
251
+ function parseBase64ToString(base64) {
252
+ try {
253
+ var binString = atob(base64);
254
+ var uint8Array = Uint8Array.from(binString, function (m) {
255
+ return m.codePointAt(0);
256
+ });
257
+ return new TextDecoder().decode(uint8Array);
258
+ } catch (error) {
259
+ return null;
260
+ }
261
+ }
262
+ export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed, parseBase64ToString };
@@ -1,10 +1,6 @@
1
- /**
2
- * @author 谦彧 <zhangmian.zm@alipay.com>
3
- * @date 2023/11/1
4
- */
5
1
  /**
6
2
  * 返回值0标识一样大,1表示v1大,-1表示v2大
7
3
  * @param v1
8
4
  * @param v2
9
5
  */
10
- export declare function compareVersion(v1: string, v2: string): 1 | -1 | 0;
6
+ export declare function compareVersion(v1: string, v2: string): 1 | 0 | -1;
@@ -1,8 +1,3 @@
1
- /**
2
- * @author 谦彧 <zhangmian.zm@alipay.com>
3
- * @date 2023/11/1
4
- */
5
-
6
1
  /**
7
2
  * 返回值0标识一样大,1表示v1大,-1表示v2大
8
3
  * @param v1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",