@alipay/ams-checkout 0.0.1755258862-dev.1 → 0.0.1755681537-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.
Files changed (99) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/component/channel.d.ts +3 -1
  3. package/esm/component/channel.js +26 -62
  4. package/esm/component/component.inline.style.js +2 -2
  5. package/esm/component/popupWindow.style.d.ts +4 -1
  6. package/esm/component/popupWindow.style.js +37 -2
  7. package/esm/config/index.d.ts +8 -8
  8. package/esm/config/index.js +8 -8
  9. package/esm/constant/easysafepay.d.ts +16 -0
  10. package/esm/constant/easysafepay.js +19 -0
  11. package/esm/constant/index.d.ts +41 -2
  12. package/esm/constant/index.js +43 -5
  13. package/esm/core/component/ckp/index.d.ts +2 -0
  14. package/esm/core/component/ckp/index.js +41 -5
  15. package/esm/core/component/element/elementContainerService/containerService.d.ts +33 -0
  16. package/esm/core/component/element/elementContainerService/containerService.js +123 -0
  17. package/esm/core/component/element/elementContainerService/index.d.ts +20 -0
  18. package/esm/core/component/element/elementContainerService/index.js +63 -0
  19. package/esm/core/component/element/elementController/index.d.ts +27 -0
  20. package/esm/core/component/element/elementController/index.js +493 -0
  21. package/esm/core/component/element/elementProcessor/addressProcessor.d.ts +20 -0
  22. package/esm/core/component/element/elementProcessor/addressProcessor.js +160 -0
  23. package/esm/core/component/element/elementProcessor/authProcessor.d.ts +20 -0
  24. package/esm/core/component/element/elementProcessor/authProcessor.js +125 -0
  25. package/esm/core/component/element/elementProcessor/baseElementProcessor.d.ts +41 -0
  26. package/esm/core/component/element/elementProcessor/baseElementProcessor.js +96 -0
  27. package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +20 -0
  28. package/esm/core/component/element/elementProcessor/paymentProcessor.js +380 -0
  29. package/esm/core/component/element/index.d.ts +7 -46
  30. package/esm/core/component/element/index.js +31 -923
  31. package/esm/core/component/element/mock.d.ts +4 -0
  32. package/esm/core/component/element/mock.js +365 -1
  33. package/esm/core/component/element/type.d.ts +74 -34
  34. package/esm/core/component/element/type.js +20 -12
  35. package/esm/core/component/element/util.d.ts +69 -0
  36. package/esm/core/component/element/util.js +477 -0
  37. package/esm/core/component/index.d.ts +5 -1
  38. package/esm/core/component/index.js +1 -2
  39. package/esm/core/component/oldElement/index.d.ts +59 -0
  40. package/esm/core/component/oldElement/index.js +956 -0
  41. package/esm/core/component/oldElement/mock.d.ts +6 -0
  42. package/esm/core/component/oldElement/mock.js +567 -0
  43. package/esm/core/component/oldElement/type.d.ts +354 -0
  44. package/esm/core/component/oldElement/type.js +81 -0
  45. package/esm/core/instance/index.d.ts +1 -1
  46. package/esm/core/instance/index.js +1 -1
  47. package/esm/foundation/core/index.d.ts +9 -1
  48. package/esm/foundation/core/index.js +153 -49
  49. package/esm/foundation/index.d.ts +20 -0
  50. package/esm/foundation/index.js +13 -2
  51. package/esm/foundation/product-processor/autoDebit/deps.d.ts +14 -0
  52. package/esm/foundation/product-processor/autoDebit/deps.js +12 -0
  53. package/esm/foundation/product-processor/autoDebit/index.d.ts +48 -0
  54. package/esm/foundation/product-processor/autoDebit/index.js +466 -0
  55. package/esm/foundation/product-processor/easysafepay/deps.d.ts +3 -1
  56. package/esm/foundation/product-processor/easysafepay/deps.js +3 -1
  57. package/esm/foundation/product-processor/easysafepay/index.d.ts +5 -0
  58. package/esm/foundation/product-processor/easysafepay/index.js +266 -138
  59. package/esm/foundation/product-processor/element/index.d.ts +7 -0
  60. package/esm/foundation/product-processor/element/index.js +24 -0
  61. package/esm/foundation/service/container/index.d.ts +14 -3
  62. package/esm/foundation/service/container/index.js +178 -25
  63. package/esm/foundation/service/container/popup.d.ts +10 -7
  64. package/esm/foundation/service/container/popup.js +3 -1
  65. package/esm/foundation/service/event-center.js +1 -0
  66. package/esm/foundation/service/log/keys.js +3 -1
  67. package/esm/foundation/service/log/types.d.ts +1 -0
  68. package/esm/foundation/service/requester/requester.js +17 -37
  69. package/esm/foundation/utils/preload_helper.d.ts +2 -2
  70. package/esm/foundation/utils/preload_helper.js +8 -4
  71. package/esm/foundation/utils/redirect_utils.js +34 -18
  72. package/esm/foundation/utils/web_app_url_utils.d.ts +71 -1
  73. package/esm/foundation/utils/web_app_url_utils.js +219 -8
  74. package/esm/index.d.ts +8 -5
  75. package/esm/index.js +103 -53
  76. package/esm/plugin/component/cashierApp.d.ts +1 -1
  77. package/esm/plugin/component/cashierApp.js +5 -5
  78. package/esm/plugin/component/channel.d.ts +3 -1
  79. package/esm/plugin/component/channel.js +10 -12
  80. package/esm/plugin/component/index.js +47 -44
  81. package/esm/plugin/type.d.ts +1 -1
  82. package/esm/request/index.js +2 -2
  83. package/esm/types/index.d.ts +37 -3
  84. package/esm/types/index.js +10 -2
  85. package/esm/util/index.d.ts +12 -1
  86. package/esm/util/index.js +39 -3
  87. package/esm/util/redirect.d.ts +6 -0
  88. package/esm/util/redirect.js +54 -0
  89. package/esm/util/spm-map.d.ts +18 -4
  90. package/esm/util/spm-map.js +20 -6
  91. package/package.json +27 -4
  92. /package/esm/core/component/{element → oldElement}/components/address.d.ts +0 -0
  93. /package/esm/core/component/{element → oldElement}/components/address.js +0 -0
  94. /package/esm/core/component/{element → oldElement}/components/auth.d.ts +0 -0
  95. /package/esm/core/component/{element → oldElement}/components/auth.js +0 -0
  96. /package/esm/core/component/{element → oldElement}/components/payment.d.ts +0 -0
  97. /package/esm/core/component/{element → oldElement}/components/payment.js +0 -0
  98. /package/esm/core/component/{element → oldElement}/utils.d.ts +0 -0
  99. /package/esm/core/component/{element → oldElement}/utils.js +0 -0
@@ -8,7 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  import { sdkVersion } from "../../config";
9
9
  import { createPreloadIframe } from "../service/container/utils";
10
10
  import { ProductSceneEnum } from "../../types";
11
- import { getWebAppUrl } from "../utils/web_app_url_utils";
11
+ import { getWebAppUrl, getWebAppV2Url } from "../utils/web_app_url_utils";
12
12
  import { ProductInfoCacheUtil } from "../utils/payment_product_utils";
13
13
  import { getWebAppVersion } from "./payment_context_utils";
14
14
  import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security } from "../../util/security";
@@ -22,12 +22,13 @@ var PreloadHelper = /*#__PURE__*/function () {
22
22
  key: "preloadWebApp",
23
23
  value: function preloadWebApp(productScene, paymentMethodCategoryType) {
24
24
  var environment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'prod';
25
+ var useV2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
25
26
  try {
26
27
  if (this.isWebAppPreloaded) {
27
28
  console.log('[web-sdk] web app already preloaded');
28
29
  return;
29
30
  }
30
- var _this$buildWebAppPrel = this.buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment),
31
+ var _this$buildWebAppPrel = this.buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment, useV2),
31
32
  preloadUrl = _this$buildWebAppPrel.preloadUrl,
32
33
  containerId = _this$buildWebAppPrel.containerId;
33
34
  var preloadIframe = createPreloadIframe(containerId);
@@ -89,6 +90,7 @@ var PreloadHelper = /*#__PURE__*/function () {
89
90
  }, {
90
91
  key: "buildWebAppPreloadUrl",
91
92
  value: function buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment) {
93
+ var useV2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
92
94
  var productSceneVersion = productScene === ProductSceneEnum.EASY_PAY ? '2.0' : '1.0';
93
95
  var previousProductInfo = ProductInfoCacheUtil.getPreviousProductInfo(productScene);
94
96
  if (previousProductInfo) {
@@ -101,14 +103,16 @@ var PreloadHelper = /*#__PURE__*/function () {
101
103
  webAppVersion: ''
102
104
  };
103
105
  sdkMetaData.webAppVersion = getWebAppVersion(sdkMetaData);
104
- var preloadUrl = getWebAppUrl({
106
+ var preloadUrlParams = {
105
107
  environment: environment,
106
108
  sdkMetaData: sdkMetaData,
107
109
  paymentMethodCategoryType: paymentMethodCategoryType,
108
110
  isPreload: true,
111
+ productScene: productScene,
109
112
  productSceneVersion: productSceneVersion,
110
113
  query: undefined
111
- });
114
+ };
115
+ var preloadUrl = useV2 ? getWebAppV2Url(preloadUrlParams) : getWebAppUrl(preloadUrlParams);
112
116
  return {
113
117
  preloadUrl: preloadUrl,
114
118
  containerId: containerId
@@ -69,26 +69,42 @@ export var redirect = function redirect(payload, instanceId) {
69
69
  successCallback(payload, type, evokeAppBy.url, serviceProvider);
70
70
  }
71
71
  });
72
+ var callApplinkUrl = function callApplinkUrl() {
73
+ try {
74
+ callAppLib.open({
75
+ link: payload.applinkUrl,
76
+ fallback: function fallback() {
77
+ failCallback(payload, RedirectType.ApplinkUrl, payload.applinkUrl, serviceProvider);
78
+ // Applink evoke failed, try to use scheme url
79
+ callSchemeUrl();
80
+ }
81
+ });
82
+ } catch (error) {
83
+ failCallback(payload, RedirectType.ApplinkUrl, payload.applinkUrl, serviceProvider);
84
+ // Applink evoke failed, try to use scheme url
85
+ callSchemeUrl();
86
+ }
87
+ };
72
88
  var callSchemeUrl = function callSchemeUrl() {
73
- callAppLib.open({
74
- scheme: payload.schemeUrl,
75
- fallback: function fallback() {
76
- failCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
77
- if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
78
- successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
79
- window.location.href = payload.url;
80
- }
81
- });
89
+ try {
90
+ callAppLib.open({
91
+ scheme: payload.schemeUrl,
92
+ fallback: function fallback() {
93
+ failCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
94
+ if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
95
+ successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
96
+ window.location.href = payload.url;
97
+ }
98
+ });
99
+ } catch (error) {
100
+ failCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
101
+ if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
102
+ successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
103
+ window.location.href = payload.url;
104
+ }
82
105
  };
83
106
  if (payload.applinkUrl) {
84
- callAppLib.open({
85
- link: payload.applinkUrl,
86
- fallback: function fallback() {
87
- failCallback(payload, RedirectType.ApplinkUrl, payload.applinkUrl, serviceProvider);
88
- // Applink evoke failed, try to use scheme url
89
- callSchemeUrl();
90
- }
91
- });
107
+ callApplinkUrl();
92
108
  } else if (payload.schemeUrl) {
93
109
  callSchemeUrl();
94
110
  }
@@ -116,7 +132,7 @@ var successCallback = function successCallback(payload, type, url, serviceProvid
116
132
  };
117
133
  var failCallback = function failCallback(payload, type, url, serviceProvider) {
118
134
  serviceProvider.getService('EventCenter').emit(EVENT.eventCallback.name, {
119
- code: eventCodeEnum.SDK_CALL_URL_ERROR,
135
+ code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
120
136
  message: "Failed to open app,applinkUrl: ".concat(payload === null || payload === void 0 ? void 0 : payload.applinkUrl, " schemeUrl: ").concat(payload === null || payload === void 0 ? void 0 : payload.schemeUrl, " normalUrl: ").concat(payload === null || payload === void 0 ? void 0 : payload.url)
121
137
  });
122
138
  serviceProvider.getService('Log').logInfo({
@@ -1,4 +1,5 @@
1
- import { DisplayTypeEnum, PaymentMethodCategoryTypeEnum } from '../../types';
1
+ import { ESP_PAGE_NAME } from '../../constant/easysafepay';
2
+ import { DisplayTypeEnum, IPaymentSessionMetaData, PaymentMethodCategoryTypeEnum, ProductSceneEnum } from '../../types';
2
3
  import { SDKMetaData } from '../index';
3
4
  /**
4
5
  * Tell the SDK which version of the Web App to load.
@@ -16,6 +17,16 @@ export interface WebAppMatchConfig {
16
17
  mid?: string;
17
18
  greyscale?: string;
18
19
  }
20
+ /**
21
+ * Tell the SDK which Web App URL to load.
22
+ * Sent by server inside paymentSession.
23
+ */
24
+ export interface WebAppUrlMatchConfig {
25
+ minSDKVersion: string;
26
+ url: string;
27
+ doubleFa: string;
28
+ mids?: string[];
29
+ }
19
30
  export interface QueryParams {
20
31
  displayType: DisplayTypeEnum;
21
32
  locale: string;
@@ -27,20 +38,79 @@ export interface QueryParams {
27
38
  export declare const getWebAppUrlInfo: (params: {
28
39
  environment: string;
29
40
  sdkMetaData: SDKMetaData;
41
+ productScene: ProductSceneEnum;
30
42
  productSceneVersion: string;
31
43
  paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
32
44
  isPreload?: boolean;
33
45
  query: QueryParams;
46
+ v2Url?: string;
34
47
  }) => {
35
48
  path: string;
36
49
  locationSearch: string;
37
50
  };
51
+ export declare const getWebAppV2Url: (params: {
52
+ environment: string;
53
+ sdkMetaData: SDKMetaData;
54
+ productScene: ProductSceneEnum;
55
+ productSceneVersion: string;
56
+ paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
57
+ isPreload?: boolean;
58
+ query: QueryParams;
59
+ mid?: string;
60
+ extendInfo?: string;
61
+ }) => string;
38
62
  export declare const getWebAppUrl: (params: {
39
63
  environment: string;
40
64
  sdkMetaData: SDKMetaData;
65
+ productScene: ProductSceneEnum;
41
66
  productSceneVersion: string;
42
67
  paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
43
68
  isPreload?: boolean;
44
69
  query: QueryParams;
70
+ v2Url?: string;
45
71
  }) => string;
46
72
  export declare const parseWebAppMatchConfig: (extendInfo: string) => WebAppMatchConfig[];
73
+ export declare const parseWebAppUrlMatchConfig: (extendInfo: string) => WebAppUrlMatchConfig[];
74
+ /**
75
+ * Save the current checkout URL to localStorage for the specified product scene.
76
+ *
77
+ * @param productScene - The product scene for which the checkout URL should be saved.
78
+ */
79
+ export declare const saveLocalCheckoutUrl: (productScene: ProductSceneEnum, url: string) => void;
80
+ /**
81
+ * 获取从外部动态下发的V2AppUrl.
82
+ *
83
+ * @param config - sessionData解析来的checkoutInfo列表.
84
+ */
85
+ export declare const getMatchedWebAppV2Url: (productScene: ProductSceneEnum, mid: string, configs: WebAppUrlMatchConfig[], env: string) => string;
86
+ /**
87
+ * 获取ESP从sessionData.checkoutInfo内动态下发的Url.
88
+ */
89
+ export declare const matchEasySafePayV2Url: (params: {
90
+ configs: WebAppUrlMatchConfig[];
91
+ mid: string;
92
+ env: string;
93
+ pageName: ESP_PAGE_NAME;
94
+ }) => string;
95
+ /**
96
+ * Retrieve the saved checkout URL from localStorage for the specified product scene.
97
+ * If no url is found, a default checkout url string is returned.
98
+ *
99
+ * @param productScene - The product scene for which the checkout URL should be retrieved.
100
+ */
101
+ export declare const getLocalCheckoutUrl: (productScene: ProductSceneEnum, environment: string) => string;
102
+ /**
103
+ * Provide default checkout URL for the specified product scene.
104
+ * Return URL for 'EASY_PAY' product scene, while for other product scenes, it returns an empty string as they are not currently in use
105
+ *
106
+ * @param productScene - The product scene for which the default checkout URL should be provided.
107
+ */
108
+ export declare const defaultCheckoutUrl: (productScene: ProductSceneEnum, environment?: string) => string;
109
+ /**
110
+ * V2应用EasySafePay 热更新兜底URL构建规则
111
+ * 1. 兜底URL版本与sdk版本保持一致
112
+ * 2. DEV环境下html新增版本前缀
113
+ **/
114
+ export declare const getDefaultEasySafePayPageUrl: (pageName: ESP_PAGE_NAME, env: string) => string;
115
+ /**通过sessionData获取doubleFa,于createComponent时传递给WEB应用*/
116
+ export declare const getDoubleFaUrlFromSession: (paymentSessionObj: IPaymentSessionMetaData, env?: string) => string;
@@ -1,25 +1,36 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  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; }
3
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
6
  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); }
5
- import { ComponentSignEnum } from "../../types";
6
- import { marmotMap } from "../../config";
7
+ import { marmotMap, sdkVersion, v2AppMarmotMap } from "../../config";
8
+ import { ESP_PAGE_NAME } from "../../constant/easysafepay";
9
+ import { ComponentSignEnum, ProductSceneEnum } from "../../types";
7
10
  import { queryParse, serialize } from "../../util";
8
11
  import { isDebugLog } from "../../util/debug";
12
+ import { compareVersion } from "../../util/versionCompare";
9
13
 
10
14
  /**
11
15
  * Tell the SDK which version of the Web App to load.
12
16
  * Sent by server inside paymentSession.
13
17
  */
14
18
 
19
+ /**
20
+ * Tell the SDK which Web App URL to load.
21
+ * Sent by server inside paymentSession.
22
+ */
23
+
15
24
  export var getWebAppUrlInfo = function getWebAppUrlInfo(params) {
16
25
  var environment = params.environment,
17
26
  sdkMetaData = params.sdkMetaData,
27
+ productScene = params.productScene,
18
28
  productSceneVersion = params.productSceneVersion,
19
29
  paymentMethodCategoryType = params.paymentMethodCategoryType,
20
30
  query = params.query,
21
- isPreload = params.isPreload;
22
- var path = getAppPath(environment, sdkMetaData, productSceneVersion, paymentMethodCategoryType);
31
+ isPreload = params.isPreload,
32
+ v2Url = params.v2Url;
33
+ var path = getAppPath(environment, sdkMetaData, productScene, productSceneVersion, paymentMethodCategoryType, v2Url);
23
34
  var _queryParse = queryParse(),
24
35
  _sandbox = _queryParse._sandbox,
25
36
  _light_sandbox = _queryParse._light_sandbox,
@@ -57,6 +68,30 @@ export var getWebAppUrlInfo = function getWebAppUrlInfo(params) {
57
68
  locationSearch: locationSearch
58
69
  };
59
70
  };
71
+ export var getWebAppV2Url = function getWebAppV2Url(params) {
72
+ var productScene = params.productScene,
73
+ isPreload = params.isPreload,
74
+ mid = params.mid,
75
+ extendInfo = params.extendInfo,
76
+ environment = params.environment;
77
+ var webAppUrlMatchConfig = parseWebAppUrlMatchConfig(extendInfo);
78
+ var v2Url = isPreload ? getLocalCheckoutUrl(productScene, environment) : getMatchedWebAppV2Url(productScene, mid, webAppUrlMatchConfig, environment);
79
+ var info = getWebAppUrlInfo(_objectSpread(_objectSpread({}, params), {}, {
80
+ v2Url: v2Url
81
+ }));
82
+ if (!isPreload && v2Url && info.path) {
83
+ console.log('[web-sdk] save web app, url: ', info.path);
84
+ saveLocalCheckoutUrl(productScene, info.path);
85
+ }
86
+ var webAppUrl;
87
+ if (info.path.indexOf('?') !== -1) {
88
+ webAppUrl = "".concat(info.path, "&").concat(info.locationSearch);
89
+ } else {
90
+ webAppUrl = "".concat(info.path, "?").concat(info.locationSearch);
91
+ }
92
+ console.log('[web-sdk] web app, url: ', webAppUrl);
93
+ return webAppUrl;
94
+ };
60
95
  export var getWebAppUrl = function getWebAppUrl(params) {
61
96
  var info = getWebAppUrlInfo(params);
62
97
  var webAppUrl;
@@ -70,8 +105,10 @@ export var getWebAppUrl = function getWebAppUrl(params) {
70
105
  var getAppPath = function getAppPath() {
71
106
  var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
72
107
  var sdkMetaData = arguments.length > 1 ? arguments[1] : undefined;
73
- var productSceneVersion = arguments.length > 2 ? arguments[2] : undefined;
74
- var paymentMethodCategoryType = arguments.length > 3 ? arguments[3] : undefined;
108
+ var productScene = arguments.length > 2 ? arguments[2] : undefined;
109
+ var productSceneVersion = arguments.length > 3 ? arguments[3] : undefined;
110
+ var paymentMethodCategoryType = arguments.length > 4 ? arguments[4] : undefined;
111
+ var v2Url = arguments.length > 5 ? arguments[5] : undefined;
75
112
  var _ref = queryParse() || {},
76
113
  urlTestHost = _ref.host;
77
114
  // only for test while testurl?host=https://xxxxx.test.html
@@ -81,7 +118,15 @@ var getAppPath = function getAppPath() {
81
118
  var validProductSceneVersion = getValidProductSceneVersion(sdkMetaData.productScene, productSceneVersion, paymentMethodCategoryType);
82
119
  var productSceneWithPaymentMethodCategoryType = "".concat(sdkMetaData.productScene, "_").concat(paymentMethodCategoryType);
83
120
  var webAppVersion = sdkMetaData.webAppVersion;
84
- return "".concat(marmotMap[environment], "/").concat(productSceneWithPaymentMethodCategoryType, "/").concat(validProductSceneVersion, "/index.").concat(webAppVersion, ".html");
121
+ if (productSceneWithPaymentMethodCategoryType === ComponentSignEnum.AUTO_DEBIT_APM) {
122
+ return "".concat(v2AppMarmotMap[environment], "/auto-debit/").concat(webAppVersion, "/pages/trustly/index.html");
123
+ }
124
+ switch (productScene) {
125
+ case ProductSceneEnum.EASY_PAY:
126
+ return v2Url !== null && v2Url !== void 0 ? v2Url : defaultCheckoutUrl(productScene, environment);
127
+ default:
128
+ return "".concat(marmotMap[environment], "/").concat(productSceneWithPaymentMethodCategoryType, "/").concat(validProductSceneVersion, "/index.").concat(webAppVersion, ".html");
129
+ }
85
130
  };
86
131
  export var parseWebAppMatchConfig = function parseWebAppMatchConfig(extendInfo) {
87
132
  if (!extendInfo) {
@@ -96,9 +141,21 @@ export var parseWebAppMatchConfig = function parseWebAppMatchConfig(extendInfo)
96
141
  return [];
97
142
  }
98
143
  };
144
+ export var parseWebAppUrlMatchConfig = function parseWebAppUrlMatchConfig(extendInfo) {
145
+ if (!extendInfo) {
146
+ return [];
147
+ }
148
+ try {
149
+ var extendInfoJson = JSON.parse(extendInfo);
150
+ return extendInfoJson === null || extendInfoJson === void 0 ? void 0 : extendInfoJson.checkoutInfo;
151
+ } catch (error) {
152
+ console.error('Parse the url config for Web app failed#', error);
153
+ return [];
154
+ }
155
+ };
99
156
  var getValidProductSceneVersion = function getValidProductSceneVersion(productScene, productSceneVer, paymentMethodCategoryType) {
100
157
  var _supportMapping;
101
- var supportMapping = (_supportMapping = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_supportMapping, ComponentSignEnum.NONE, ['']), ComponentSignEnum.AUTO_DEBIT_WALLET, ['1.0']), ComponentSignEnum.AUTO_DEBIT_PAY_WALLET, ['']), ComponentSignEnum.CASHIER_PAYMENT_BANK, ['1.0']), ComponentSignEnum.CASHIER_PAYMENT_CARD, ['1.0']), ComponentSignEnum.CASHIER_PAYMENT_APM, ['1.0']), ComponentSignEnum.EASY_PAY_WALLET, ['1.0', '2.0']), ComponentSignEnum.EASY_PAY_APM, ['2.0']), ComponentSignEnum.VAULTING_CARD, ['1.0']), ComponentSignEnum.ELEMENT_PAYMENT, ['1.0']), _defineProperty(_defineProperty(_supportMapping, ComponentSignEnum.ELEMENT_ADDRESS, ['1.0']), ComponentSignEnum.CHECKOUT_PAYMENT, ['1.0']));
158
+ var supportMapping = (_supportMapping = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_supportMapping, ComponentSignEnum.NONE, ['']), ComponentSignEnum.AUTO_DEBIT_WALLET, ['1.0']), ComponentSignEnum.AUTO_DEBIT_PAY_WALLET, ['']), ComponentSignEnum.CASHIER_PAYMENT_BANK, ['1.0']), ComponentSignEnum.CASHIER_PAYMENT_CARD, ['1.0']), ComponentSignEnum.CASHIER_PAYMENT_APM, ['1.0']), ComponentSignEnum.EASY_PAY_WALLET, ['1.0', '2.0']), ComponentSignEnum.EASY_PAY_APM, ['2.0']), ComponentSignEnum.VAULTING_CARD, ['1.0']), ComponentSignEnum.ELEMENT_PAYMENT, ['1.0']), _defineProperty(_defineProperty(_defineProperty(_supportMapping, ComponentSignEnum.ELEMENT_ADDRESS, ['1.0']), ComponentSignEnum.CHECKOUT_PAYMENT, ['1.0']), ComponentSignEnum.AUTO_DEBIT_APM, ['1.0']));
102
159
  var targetVersions = supportMapping[productScene + '_' + paymentMethodCategoryType];
103
160
  if (!targetVersions) {
104
161
  return '';
@@ -109,4 +166,158 @@ var getValidProductSceneVersion = function getValidProductSceneVersion(productSc
109
166
  });
110
167
  var latestVersion = targetVersions[targetVersions.length - 1];
111
168
  return isSupport ? productSceneVer : latestVersion;
169
+ };
170
+ var KEY_CHECKOUT_URL = "web_url_";
171
+
172
+ /**
173
+ * Save the current checkout URL to localStorage for the specified product scene.
174
+ *
175
+ * @param productScene - The product scene for which the checkout URL should be saved.
176
+ */
177
+ export var saveLocalCheckoutUrl = function saveLocalCheckoutUrl(productScene, url) {
178
+ var key = KEY_CHECKOUT_URL + productScene;
179
+ localStorage.setItem(key, url);
180
+ };
181
+
182
+ /**
183
+ * 获取从外部动态下发的V2AppUrl.
184
+ *
185
+ * @param config - sessionData解析来的checkoutInfo列表.
186
+ */
187
+ export var getMatchedWebAppV2Url = function getMatchedWebAppV2Url(productScene) {
188
+ var mid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
189
+ var configs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
190
+ var env = arguments.length > 3 ? arguments[3] : undefined;
191
+ switch (productScene) {
192
+ case ProductSceneEnum.EASY_PAY:
193
+ return matchEasySafePayV2Url({
194
+ configs: configs,
195
+ mid: mid,
196
+ env: env,
197
+ pageName: ESP_PAGE_NAME.SDK_PORTAL
198
+ });
199
+ default:
200
+ return defaultCheckoutUrl(productScene, env);
201
+ }
202
+ };
203
+
204
+ /**
205
+ * 获取ESP从sessionData.checkoutInfo内动态下发的Url.
206
+ */
207
+ export var matchEasySafePayV2Url = function matchEasySafePayV2Url(params) {
208
+ var _params$configs = params.configs,
209
+ configs = _params$configs === void 0 ? [] : _params$configs,
210
+ _params$mid = params.mid,
211
+ mid = _params$mid === void 0 ? '' : _params$mid,
212
+ env = params.env,
213
+ pageName = params.pageName;
214
+ var matchURLByMid = function matchURLByMid() {
215
+ var sortedConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
216
+ var targetConfigEntry = sortedConfigs.find(function (configEntry) {
217
+ var _configEntry$mids;
218
+ var isMatchMid = !!(configEntry !== null && configEntry !== void 0 && (_configEntry$mids = configEntry.mids) !== null && _configEntry$mids !== void 0 && _configEntry$mids.includes(mid));
219
+ var isMatchVersion = compareVersion(sdkVersion, configEntry.minSDKVersion) >= 0;
220
+ if (isMatchMid && isMatchVersion) {
221
+ return configEntry;
222
+ }
223
+ });
224
+ return targetConfigEntry;
225
+ };
226
+ var matchURLBySDKVersion = function matchURLBySDKVersion() {
227
+ var sortedConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
228
+ var targetConfigEntry = sortedConfigs.find(function (configEntry) {
229
+ var isCommonConfig = (configEntry === null || configEntry === void 0 ? void 0 : configEntry.mids) === undefined;
230
+ var isMatchVersion = compareVersion(sdkVersion, configEntry.minSDKVersion) >= 0;
231
+ if (isCommonConfig && isMatchVersion) {
232
+ return configEntry;
233
+ }
234
+ });
235
+ return targetConfigEntry;
236
+ };
237
+ var matchConfig = function matchConfig() {
238
+ // 按SDK版本降排序
239
+ var sortedConfig = configs.sort(function (a, b) {
240
+ return compareVersion(b.minSDKVersion, a.minSDKVersion);
241
+ });
242
+
243
+ // 匹配仅针对部分商户生效(mid),且符合版本号的URL
244
+ var matchedURLByMid = matchURLByMid(sortedConfig);
245
+ if (matchedURLByMid) return matchedURLByMid;
246
+
247
+ // 匹配对所有商户生效(无mid),且符合版本号的URL
248
+ var matchedURLBySDKVersion = matchURLBySDKVersion(sortedConfig);
249
+ if (matchedURLBySDKVersion) return matchedURLBySDKVersion;
250
+ };
251
+ var defaultEspUrl = getDefaultEasySafePayPageUrl(pageName, env);
252
+
253
+ // 匹配config
254
+ var config = matchConfig();
255
+ if (!config) return defaultEspUrl;
256
+
257
+ // 根据pageName匹配URL
258
+ if (pageName === ESP_PAGE_NAME.SDK_PORTAL) return (config === null || config === void 0 ? void 0 : config.url) || defaultEspUrl;
259
+ if (pageName === ESP_PAGE_NAME.DOUBLE_FA) return (config === null || config === void 0 ? void 0 : config.doubleFa) || defaultEspUrl;
260
+ return defaultEspUrl;
261
+ };
262
+
263
+ /**
264
+ * Retrieve the saved checkout URL from localStorage for the specified product scene.
265
+ * If no url is found, a default checkout url string is returned.
266
+ *
267
+ * @param productScene - The product scene for which the checkout URL should be retrieved.
268
+ */
269
+ export var getLocalCheckoutUrl = function getLocalCheckoutUrl(productScene, environment) {
270
+ var key = KEY_CHECKOUT_URL + productScene;
271
+ var previousCheckoutUrl = localStorage.getItem(key);
272
+ return previousCheckoutUrl !== null && previousCheckoutUrl !== void 0 ? previousCheckoutUrl : defaultCheckoutUrl(productScene, environment);
273
+ };
274
+
275
+ /**
276
+ * Provide default checkout URL for the specified product scene.
277
+ * Return URL for 'EASY_PAY' product scene, while for other product scenes, it returns an empty string as they are not currently in use
278
+ *
279
+ * @param productScene - The product scene for which the default checkout URL should be provided.
280
+ */
281
+ export var defaultCheckoutUrl = function defaultCheckoutUrl(productScene) {
282
+ var environment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'prod';
283
+ switch (productScene) {
284
+ case ProductSceneEnum.EASY_PAY:
285
+ return getDefaultEasySafePayPageUrl(ESP_PAGE_NAME.SDK_PORTAL, environment);
286
+ default:
287
+ return '';
288
+ }
289
+ };
290
+
291
+ /**
292
+ * V2应用EasySafePay 热更新兜底URL构建规则
293
+ * 1. 兜底URL版本与sdk版本保持一致
294
+ * 2. DEV环境下html新增版本前缀
295
+ **/
296
+ export var getDefaultEasySafePayPageUrl = function getDefaultEasySafePayPageUrl(pageName, env) {
297
+ // 生成的URL EXAMPLE:
298
+ // const DEFAULT_DOUBLE_FA_URL_MAPPING = {
299
+ // local: 'http://page.alipay.net/page/antom-web-checkout-v2/easysafepay/1.36.0/pages/double-fa/index-1.36.0.html',
300
+ // dev: 'http://page.alipay.net/page/antom-web-checkout-v2/easysafepay/1.36.0/pages/double-fa/index-1.36.0.html',
301
+ // sit: 'http://page.test.alipay.net/page/antom-web-checkout-v2/easysafepay/1.36.0/pages/double-fa/index.html',
302
+ // pre: 'https://pre.ac.alipay.com/page/antom-web-checkout-v2/easysafepay/1.36.0/pages/double-fa/index.html',
303
+ // prod: 'https://checkout.antom.com/easysafepay/1.36.0/pages/double-fa/index.html',
304
+ // };
305
+ var environment = env || 'prod';
306
+ if (environment === 'dev') return "".concat(v2AppMarmotMap[environment], "/easysafepay/").concat(sdkVersion, "/pages/").concat(pageName, "/index-").concat(sdkVersion, ".html");else return "".concat(v2AppMarmotMap[environment], "/easysafepay/").concat(sdkVersion, "/pages/").concat(pageName, "/index.html");
307
+ };
308
+
309
+ /**通过sessionData获取doubleFa,于createComponent时传递给WEB应用*/
310
+ //TODO 后续需要构造一个类,专门用于构造&存储web应用url
311
+ export var getDoubleFaUrlFromSession = function getDoubleFaUrlFromSession(paymentSessionObj) {
312
+ var env = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'prod';
313
+ var mid = paymentSessionObj.clientId;
314
+ var extendInfo = paymentSessionObj.extendInfo;
315
+ var configs = parseWebAppUrlMatchConfig(extendInfo);
316
+ var url = matchEasySafePayV2Url({
317
+ configs: configs,
318
+ mid: mid,
319
+ env: env,
320
+ pageName: ESP_PAGE_NAME.DOUBLE_FA
321
+ });
322
+ return url;
112
323
  };
package/esm/index.d.ts CHANGED
@@ -7,10 +7,6 @@ export * from './types';
7
7
  export declare class AMSCheckout extends AMSComponent {
8
8
  constructor(_options: IoptionsParams, channelType?: ComponentSignEnum[], productSceneVersion?: string);
9
9
  }
10
- export declare class AMSAutoDebit extends AMSCheckout {
11
- constructor(options: IoptionsParams);
12
- static preload(options?: IPreloadOptions): void;
13
- }
14
10
  export declare class AMSAutoDebitPay extends AMSCheckout {
15
11
  constructor(options: IoptionsParams);
16
12
  static preload(options?: IPreloadOptions): void;
@@ -29,7 +25,7 @@ export declare class AntomElement extends AMSCheckout {
29
25
  export declare class AddressElement extends AddressComponent {
30
26
  constructor(options: IoptionsAddressParams);
31
27
  }
32
- export declare class Element extends ElementComponent {
28
+ export declare class AMSElement extends ElementComponent {
33
29
  constructor(options: IElementOptions);
34
30
  }
35
31
  export declare class AMSEasyPay {
@@ -39,4 +35,11 @@ export declare class AMSEasyPay {
39
35
  createComponent(params: IcreateComponent): void;
40
36
  unmount(): void;
41
37
  }
38
+ export declare class AMSAutoDebit {
39
+ private core;
40
+ constructor(options: IoptionsParams);
41
+ createComponent(params: IcreateComponent): Promise<void>;
42
+ unmount(): void;
43
+ static preload(options?: IPreloadOptions): void;
44
+ }
42
45
  export default AMSCheckout;