@alipay/ams-checkout 0.0.1726734012-dev.1 → 0.0.1726734012-dev.10

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 (145) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/component/channel.d.ts +19 -0
  3. package/esm/component/channel.js +87 -0
  4. package/esm/component/component.inline.style.d.ts +10 -0
  5. package/esm/component/component.inline.style.js +121 -0
  6. package/esm/component/component.popup.style.d.ts +25 -0
  7. package/esm/component/component.popup.style.js +203 -0
  8. package/esm/component/popupWindow.style.d.ts +11 -0
  9. package/esm/component/popupWindow.style.js +121 -0
  10. package/esm/config/index.d.ts +11 -0
  11. package/esm/config/index.js +20 -1
  12. package/esm/constant/index.d.ts +25 -0
  13. package/esm/constant/index.js +28 -0
  14. package/esm/core/bus/index.d.ts +3 -3
  15. package/esm/core/bus/index.js +14 -14
  16. package/esm/core/component/address.d.ts +8 -0
  17. package/esm/core/component/address.js +72 -0
  18. package/esm/core/component/appPreloadProcessing.js +2 -2
  19. package/esm/core/component/ckp/index.js +12 -8
  20. package/esm/core/component/element/components/address.d.ts +19 -0
  21. package/esm/core/component/element/components/address.js +68 -0
  22. package/esm/core/component/element/components/auth.d.ts +17 -0
  23. package/esm/core/component/element/components/auth.js +60 -0
  24. package/esm/core/component/element/components/payment.d.ts +19 -0
  25. package/esm/core/component/element/components/payment.js +74 -0
  26. package/esm/core/component/element/index.d.ts +47 -0
  27. package/esm/core/component/element/index.js +817 -0
  28. package/esm/core/component/element/mock.d.ts +4 -0
  29. package/esm/core/component/element/mock.js +491 -0
  30. package/esm/core/component/element/type.d.ts +191 -0
  31. package/esm/core/component/element/type.js +36 -0
  32. package/esm/core/component/element/utils.d.ts +13 -0
  33. package/esm/core/component/element/utils.js +6 -0
  34. package/esm/core/component/index.d.ts +14 -7
  35. package/esm/core/component/index.js +137 -78
  36. package/esm/core/drop-in/index.js +2 -2
  37. package/esm/core/instance/index.d.ts +2 -1
  38. package/esm/core/instance/index.js +27 -12
  39. package/esm/foundation/core/index.d.ts +28 -0
  40. package/esm/foundation/core/index.js +396 -0
  41. package/esm/foundation/index.d.ts +75 -0
  42. package/esm/foundation/index.js +42 -0
  43. package/esm/foundation/product-processor/easysafepay/deps.d.ts +18 -0
  44. package/esm/foundation/product-processor/easysafepay/deps.js +12 -0
  45. package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
  46. package/esm/foundation/product-processor/easysafepay/index.js +464 -0
  47. package/esm/foundation/service/api-bus/ability/callback.d.ts +9 -0
  48. package/esm/foundation/service/api-bus/ability/callback.js +55 -0
  49. package/esm/foundation/service/api-bus/ability/globalData.d.ts +10 -0
  50. package/esm/foundation/service/api-bus/ability/globalData.js +89 -0
  51. package/esm/foundation/service/api-bus/ability/request.d.ts +10 -0
  52. package/esm/foundation/service/api-bus/ability/request.js +151 -0
  53. package/esm/foundation/service/api-bus/ability/security.d.ts +12 -0
  54. package/esm/foundation/service/api-bus/ability/security.js +161 -0
  55. package/esm/foundation/service/api-bus/ability/tracker.d.ts +9 -0
  56. package/esm/foundation/service/api-bus/ability/tracker.js +80 -0
  57. package/esm/foundation/service/api-bus/busManager.d.ts +127 -0
  58. package/esm/foundation/service/api-bus/busManager.js +398 -0
  59. package/esm/foundation/service/api-bus/index.d.ts +20 -0
  60. package/esm/foundation/service/api-bus/index.js +88 -0
  61. package/esm/foundation/service/api-bus/interface.d.ts +48 -0
  62. package/esm/foundation/service/api-bus/interface.js +54 -0
  63. package/esm/foundation/service/container/index.d.ts +32 -0
  64. package/esm/foundation/service/container/index.js +332 -0
  65. package/esm/foundation/service/container/popup.d.ts +17 -0
  66. package/esm/foundation/service/container/popup.js +103 -0
  67. package/esm/foundation/service/container/utils.d.ts +7 -0
  68. package/esm/foundation/service/container/utils.js +48 -0
  69. package/esm/foundation/service/event-center.d.ts +82 -0
  70. package/esm/foundation/service/event-center.js +274 -0
  71. package/esm/foundation/service/global-data/index.d.ts +11 -0
  72. package/esm/foundation/service/global-data/index.js +68 -0
  73. package/esm/foundation/service/index.d.ts +19 -0
  74. package/esm/foundation/service/index.js +82 -0
  75. package/esm/foundation/service/log/index.d.ts +43 -0
  76. package/esm/foundation/service/log/index.js +250 -0
  77. package/esm/foundation/service/log/keys.d.ts +13 -0
  78. package/esm/foundation/service/log/keys.js +103 -0
  79. package/esm/foundation/service/log/processor.d.ts +9 -0
  80. package/esm/foundation/service/log/processor.js +148 -0
  81. package/esm/foundation/service/log/types.d.ts +32 -0
  82. package/esm/foundation/service/log/types.js +1 -0
  83. package/esm/foundation/service/requester/deps.d.ts +17 -0
  84. package/esm/foundation/service/requester/deps.js +11 -0
  85. package/esm/foundation/service/requester/requester.d.ts +22 -0
  86. package/esm/foundation/service/requester/requester.js +217 -0
  87. package/esm/foundation/service/security/index.d.ts +28 -0
  88. package/esm/foundation/service/security/index.js +284 -0
  89. package/esm/foundation/service/security/security.d.ts +33 -0
  90. package/esm/foundation/service/security/security.js +182 -0
  91. package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
  92. package/esm/foundation/utils/gray_scale_utils.js +40 -0
  93. package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
  94. package/esm/foundation/utils/payment_context_utils.js +57 -0
  95. package/esm/foundation/utils/payment_product_utils.d.ts +13 -0
  96. package/esm/foundation/utils/payment_product_utils.js +38 -0
  97. package/esm/foundation/utils/redirect_utils.d.ts +11 -0
  98. package/esm/foundation/utils/redirect_utils.js +262 -0
  99. package/esm/foundation/utils/system_events.d.ts +4 -0
  100. package/esm/foundation/utils/system_events.js +66 -0
  101. package/esm/foundation/utils/web_app_url_utils.d.ts +46 -0
  102. package/esm/foundation/utils/web_app_url_utils.js +112 -0
  103. package/esm/index.d.ts +21 -12
  104. package/esm/index.js +116 -56
  105. package/esm/plugin/applepay/component.js +13 -11
  106. package/esm/plugin/applepay/index.js +10 -6
  107. package/esm/plugin/applepay/service.d.ts +2 -2
  108. package/esm/plugin/applepay/service.js +26 -18
  109. package/esm/plugin/component/cashierApp.d.ts +10 -8
  110. package/esm/plugin/component/cashierApp.js +48 -11
  111. package/esm/plugin/component/channel.d.ts +4 -3
  112. package/esm/plugin/component/channel.js +39 -2
  113. package/esm/plugin/component/component.inline.style.d.ts +9 -10
  114. package/esm/plugin/component/component.inline.style.js +93 -10
  115. package/esm/plugin/component/component.popup.style.d.ts +15 -6
  116. package/esm/plugin/component/component.popup.style.js +30 -7
  117. package/esm/plugin/component/index.d.ts +14 -8
  118. package/esm/plugin/component/index.js +384 -187
  119. package/esm/plugin/component/popupWindow.style.d.ts +5 -2
  120. package/esm/plugin/component/popupWindow.style.js +70 -14
  121. package/esm/plugin/const.js +5 -5
  122. package/esm/plugin/drop-in/index.d.ts +5 -5
  123. package/esm/plugin/drop-in/index.js +7 -7
  124. package/esm/plugin/payment-element/utils.d.ts +2 -0
  125. package/esm/plugin/payment-element/utils.js +6 -0
  126. package/esm/plugin/paypal/index.js +2 -1
  127. package/esm/plugin/type.d.ts +4 -3
  128. package/esm/service/element.d.ts +4 -0
  129. package/esm/service/element.js +51 -0
  130. package/esm/service/index.d.ts +1 -0
  131. package/esm/service/index.js +6 -2
  132. package/esm/types/index.d.ts +339 -40
  133. package/esm/types/index.js +119 -55
  134. package/esm/util/createIframeNode.d.ts +2 -2
  135. package/esm/util/createIframeNode.js +3 -3
  136. package/esm/util/getBackScheme.d.ts +5 -0
  137. package/esm/util/getBackScheme.js +133 -0
  138. package/esm/util/index.js +4 -8
  139. package/esm/util/logger.d.ts +3 -3
  140. package/esm/util/logger.js +49 -13
  141. package/esm/util/security.d.ts +3 -2
  142. package/esm/util/security.js +2 -2
  143. package/esm/util/spm-map.d.ts +172 -0
  144. package/esm/util/spm-map.js +172 -0
  145. package/package.json +3 -1
@@ -0,0 +1,88 @@
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; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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 { EnvironmentEnum } from "../../../types";
11
+ import { TrackerBusSubscriber } from "./ability/tracker";
12
+ import { ServiceProvider } from '..';
13
+ import { SecurityBusSubscriber } from "./ability/security";
14
+ import { DataBusSubscriber } from "./ability/globalData";
15
+ import { RequestBusSubscriber } from "./ability/request";
16
+ import { BusManager } from "./busManager";
17
+
18
+ /**
19
+ * @author 谦彧 <zhangmian.zm@alipay.com>
20
+ * @date 2024/9/17
21
+ */
22
+ export var ApiBusManagerService = /*#__PURE__*/function () {
23
+ function ApiBusManagerService() {
24
+ _classCallCheck(this, ApiBusManagerService);
25
+ _defineProperty(this, "logger", void 0);
26
+ _defineProperty(this, "instanceId", void 0);
27
+ _defineProperty(this, "busManager", void 0);
28
+ }
29
+ _createClass(ApiBusManagerService, [{
30
+ key: "init",
31
+ value: function init(initOptions, instanceId) {
32
+ var _this = this;
33
+ this.instanceId = instanceId;
34
+ this.logger = ServiceProvider.getInstance(this.instanceId).getService('Log');
35
+ this.busManager = new BusManager(this.instanceId);
36
+ this.busManager.debugTrace((initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment) !== EnvironmentEnum.prod);
37
+ this.busManager.clear();
38
+ // addInterceptor
39
+ this.busManager.addInterceptor({
40
+ onPublishException: function onPublishException(message, e) {
41
+ _this.logger.logError({
42
+ title: 'onBusPublishException'
43
+ }, _objectSpread(_objectSpread({}, message), {}, {
44
+ errorMessage: JSON.stringify(e)
45
+ }));
46
+ }
47
+ });
48
+ // subscribe basic ability TODO
49
+ // this.busManager.subscribe(
50
+ // new SDKCallbackBusSubscriber((state: { code: string; message?: string; result?: EventCallbackResult }) => {
51
+ // const eventCenter = ServiceProvider.getInstance(this.instanceId).getService<EventCenter>('EventCenter');
52
+ // eventCenter.emit(EVENT.eventCallback.name, state);
53
+ // }),
54
+ // );
55
+ this.busManager.subscribe(new SecurityBusSubscriber(this.instanceId));
56
+ this.busManager.subscribe(new TrackerBusSubscriber(this.instanceId));
57
+ this.busManager.subscribe(new DataBusSubscriber(this.instanceId));
58
+ this.busManager.subscribe(new RequestBusSubscriber(this.instanceId));
59
+ }
60
+ }, {
61
+ key: "subscribe",
62
+ value: function subscribe(subscriber) {
63
+ this.busManager.subscribe(subscriber);
64
+ }
65
+ }, {
66
+ key: "unsubscribe",
67
+ value: function unsubscribe(subscriber) {
68
+ this.busManager.unsubscribe(subscriber);
69
+ }
70
+ }, {
71
+ key: "isSubscribed",
72
+ value: function isSubscribed(actionName) {
73
+ return this.busManager.isSubscribed(actionName);
74
+ }
75
+ }, {
76
+ key: "publish",
77
+ value: function publish(message, callback) {
78
+ this.busManager.publish(message, callback);
79
+ }
80
+ }, {
81
+ key: "update",
82
+ value: function update() {}
83
+ }, {
84
+ key: "destroy",
85
+ value: function destroy() {}
86
+ }]);
87
+ return ApiBusManagerService;
88
+ }();
@@ -0,0 +1,48 @@
1
+ export declare enum PaymentActionEnum {
2
+ optional_init = "plugin_optional_init"
3
+ }
4
+ export declare enum ApplePayActionEnum {
5
+ canMakePayments = "plugin_CARD_APPLE_PAY_available",
6
+ createComponent = "plugin_CARD_APPLE_PAY_createComponent",
7
+ destroyComponent = "plugin_CARD_APPLE_PAY_destroyComponent"
8
+ }
9
+ export declare enum PaypalActionEnum {
10
+ mountComponent = "plugin_Paypal_mountComponent",
11
+ destroyComponent = "plugin_Paypal_destroyComponent"
12
+ }
13
+ export declare enum SDKCallbackActionEnum {
14
+ onEventCallback = "onEventCallback"
15
+ }
16
+ export declare enum RequestActiontEnum {
17
+ request = "request",
18
+ getEnvInfo = "getEnvInfo",
19
+ getUserAgent = "getUserAgent"
20
+ }
21
+ export declare enum DataActiontEnum {
22
+ getGlobalData = "getGlobalData",
23
+ setGlobalData = "setGlobalData",
24
+ clearGlobalData = "clearGlobalData"
25
+ }
26
+ export declare enum SecuritySDKActionEnum {
27
+ preInitSecurity = "preInitSecurity",
28
+ initSecurity = "initSecurity",
29
+ getSecurityDeviceId = "getSecurityDeviceId"
30
+ }
31
+ export declare enum TrackerActionEnum {
32
+ /**
33
+ * level: string info/error
34
+ * basic: json object
35
+ * extra: json object
36
+ */
37
+ reportAnalytics = "reportAnalytics"
38
+ }
39
+ export declare enum ComponentActiontEnum {
40
+ onDestory = "onDestory"
41
+ }
42
+ export declare enum RequestActiontEnum {
43
+ onDestory = "httpRequest"
44
+ }
45
+ export declare enum LoadingActiontEnum {
46
+ showLoading = "showLoading",
47
+ dismissLoading = "dismissLoading"
48
+ }
@@ -0,0 +1,54 @@
1
+ export var PaymentActionEnum = /*#__PURE__*/function (PaymentActionEnum) {
2
+ PaymentActionEnum["optional_init"] = "plugin_optional_init";
3
+ return PaymentActionEnum;
4
+ }({});
5
+ export var ApplePayActionEnum = /*#__PURE__*/function (ApplePayActionEnum) {
6
+ ApplePayActionEnum["canMakePayments"] = "plugin_CARD_APPLE_PAY_available";
7
+ ApplePayActionEnum["createComponent"] = "plugin_CARD_APPLE_PAY_createComponent";
8
+ ApplePayActionEnum["destroyComponent"] = "plugin_CARD_APPLE_PAY_destroyComponent";
9
+ return ApplePayActionEnum;
10
+ }({});
11
+ export var PaypalActionEnum = /*#__PURE__*/function (PaypalActionEnum) {
12
+ PaypalActionEnum["mountComponent"] = "plugin_Paypal_mountComponent";
13
+ PaypalActionEnum["destroyComponent"] = "plugin_Paypal_destroyComponent";
14
+ return PaypalActionEnum;
15
+ }({});
16
+ export var SDKCallbackActionEnum = /*#__PURE__*/function (SDKCallbackActionEnum) {
17
+ SDKCallbackActionEnum["onEventCallback"] = "onEventCallback";
18
+ return SDKCallbackActionEnum;
19
+ }({});
20
+ export var RequestActiontEnum = /*#__PURE__*/function (RequestActiontEnum) {
21
+ RequestActiontEnum["request"] = "request";
22
+ RequestActiontEnum["getEnvInfo"] = "getEnvInfo";
23
+ RequestActiontEnum["getUserAgent"] = "getUserAgent";
24
+ return RequestActiontEnum;
25
+ }({});
26
+ export var DataActiontEnum = /*#__PURE__*/function (DataActiontEnum) {
27
+ DataActiontEnum["getGlobalData"] = "getGlobalData";
28
+ DataActiontEnum["setGlobalData"] = "setGlobalData";
29
+ DataActiontEnum["clearGlobalData"] = "clearGlobalData";
30
+ return DataActiontEnum;
31
+ }({});
32
+ export var SecuritySDKActionEnum = /*#__PURE__*/function (SecuritySDKActionEnum) {
33
+ SecuritySDKActionEnum["preInitSecurity"] = "preInitSecurity";
34
+ SecuritySDKActionEnum["initSecurity"] = "initSecurity";
35
+ SecuritySDKActionEnum["getSecurityDeviceId"] = "getSecurityDeviceId";
36
+ return SecuritySDKActionEnum;
37
+ }({});
38
+ export var TrackerActionEnum = /*#__PURE__*/function (TrackerActionEnum) {
39
+ TrackerActionEnum["reportAnalytics"] = "reportAnalytics";
40
+ return TrackerActionEnum;
41
+ }({});
42
+ export var ComponentActiontEnum = /*#__PURE__*/function (ComponentActiontEnum) {
43
+ ComponentActiontEnum["onDestory"] = "onDestory";
44
+ return ComponentActiontEnum;
45
+ }({});
46
+ RequestActiontEnum = /*#__PURE__*/function (RequestActiontEnum) {
47
+ RequestActiontEnum["onDestory"] = "httpRequest";
48
+ return RequestActiontEnum;
49
+ }(RequestActiontEnum || {});
50
+ export var LoadingActiontEnum = /*#__PURE__*/function (LoadingActiontEnum) {
51
+ LoadingActiontEnum["showLoading"] = "showLoading";
52
+ LoadingActiontEnum["dismissLoading"] = "dismissLoading";
53
+ return LoadingActiontEnum;
54
+ }({});
@@ -0,0 +1,32 @@
1
+ import { DisplayInfo, SDKMetaData, Service } from '../../index';
2
+ import { IoptionsParams } from '../../../types';
3
+ export declare class ContainerService implements Service {
4
+ private instanceId;
5
+ private sdkMetaData;
6
+ private clearTimerIdMapping;
7
+ private popupManager;
8
+ private eventCenter;
9
+ private logService;
10
+ private displayInfo;
11
+ private webApp;
12
+ private _webAppHeartBeatTimeoutFn;
13
+ private customizedLoadingListener;
14
+ destroy(): void;
15
+ init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
16
+ update(): void;
17
+ load(displayInfo: DisplayInfo, url: string, closeBtnFunc: () => void): HTMLDivElement;
18
+ cleanContainer(displayInfo: DisplayInfo): void;
19
+ preload(taskId: string, url: string): void;
20
+ clearPreloadContainer(taskId: string): void;
21
+ showLoading(container: HTMLDivElement, displayInfo: DisplayInfo): void;
22
+ dismissLoading(isKeepMockup?: boolean): void;
23
+ customizeLoading(listener: (event: 'SDK_START_OF_LOADING' | 'SDK_END_OF_LOADING') => void): void;
24
+ startHideAnim(): void;
25
+ private addCapabilityToEventCenter;
26
+ private addCapabilityToApiBusManager;
27
+ private updateMaskCloseBtn;
28
+ private handleSizeChanged;
29
+ private handleAppHeartBeat;
30
+ private changeCloseBtnVisibility;
31
+ private handleMaskCloseBtnShow;
32
+ }
@@ -0,0 +1,332 @@
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; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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 { DisplayTypeEnum } from "../../../types";
11
+ import { createIframe, createPreloadIframe, startSizeChangeAnim } from "./utils";
12
+ import { addInlineLoading, createInlineBaseElement } from "../../../component/component.inline.style";
13
+ import { addPopupLoading, createBaseElement } from "../../../component/component.popup.style";
14
+ import { COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CLOSE_MASK_BLOCK_ID, COMPONENT_CONTAINER_ID, ERRORMESSAGE, LOADING_ID, MOCKUP_ID } from "../../../constant";
15
+ import { ServiceProvider } from "../index";
16
+ import { EVENT, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../../constant";
17
+ import { PopupManager } from "./popup";
18
+ /**
19
+ * @author 谦彧 <zhangmian.zm@alipay.com>
20
+ * @date 2024/9/17
21
+ */
22
+ var MAX_CLEAR_TIME = 10000;
23
+ export var ContainerService = /*#__PURE__*/function () {
24
+ function ContainerService() {
25
+ _classCallCheck(this, ContainerService);
26
+ _defineProperty(this, "instanceId", void 0);
27
+ _defineProperty(this, "sdkMetaData", void 0);
28
+ _defineProperty(this, "clearTimerIdMapping", {});
29
+ _defineProperty(this, "popupManager", void 0);
30
+ _defineProperty(this, "eventCenter", void 0);
31
+ _defineProperty(this, "logService", void 0);
32
+ _defineProperty(this, "displayInfo", void 0);
33
+ _defineProperty(this, "webApp", void 0);
34
+ _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
35
+ // if this variable is true, SDK will invoke listener instead of showing loading
36
+ _defineProperty(this, "customizedLoadingListener", void 0);
37
+ }
38
+ _createClass(ContainerService, [{
39
+ key: "destroy",
40
+ value: function destroy() {}
41
+ }, {
42
+ key: "init",
43
+ value: function init(initOptions, instanceId, sdkMetaData) {
44
+ this.instanceId = instanceId;
45
+ this.sdkMetaData = sdkMetaData;
46
+ this.eventCenter = ServiceProvider.getInstance(instanceId).getService('EventCenter');
47
+ this.logService = ServiceProvider.getInstance(instanceId).getService('Log');
48
+ this.popupManager = new PopupManager();
49
+ this.addCapabilityToEventCenter();
50
+ this.addCapabilityToApiBusManager();
51
+ }
52
+ }, {
53
+ key: "update",
54
+ value: function update() {}
55
+ }, {
56
+ key: "load",
57
+ value: function load(displayInfo, url, closeBtnFunc) {
58
+ var webApp = createIframe('antom-sdk-web-app' + (displayInfo.appendAliasContainerId ? "-".concat(displayInfo.selector) : ''));
59
+ this.webApp = webApp;
60
+ this.displayInfo = displayInfo;
61
+ webApp.src = url;
62
+ this.eventCenter.addIFrame(webApp);
63
+ if (webApp.src.includes('?')) {
64
+ this.popupManager.setPopupUrlQuery(webApp.src.split('?')[1]);
65
+ }
66
+ // TODO call ApiBusManager to add listener to iframe, componentApp line 979
67
+
68
+ // create container and append web app
69
+ var container = displayInfo.type === DisplayTypeEnum.inline ? createInlineBaseElement(displayInfo.selector) : createBaseElement(displayInfo.platform, closeBtnFunc);
70
+ container.appendChild(webApp);
71
+ return container;
72
+ }
73
+ }, {
74
+ key: "cleanContainer",
75
+ value: function cleanContainer(displayInfo) {
76
+ var _document$getElementB;
77
+ // selector and container
78
+ var selector = displayInfo.type === DisplayTypeEnum.inline ? displayInfo.selector : COMPONENT_CONTAINER_ID;
79
+ var selectorDom = document.querySelector(selector);
80
+ if (selectorDom) {
81
+ selectorDom.innerHTML = '';
82
+ }
83
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
84
+ if (container) container === null || container === void 0 || container.remove();
85
+ this.webApp = null;
86
+ this.eventCenter.cleanIFrames();
87
+
88
+ // animation
89
+ (_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(displayInfo.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
90
+ }
91
+ }, {
92
+ key: "preload",
93
+ value: function preload(taskId, url) {
94
+ var _this = this;
95
+ var preloadIframe = createPreloadIframe(taskId);
96
+ preloadIframe.src = url;
97
+ var body = document.body || null;
98
+ if (body) {
99
+ body.appendChild(preloadIframe);
100
+ }
101
+ console.log('web-preloadsdk web app', url);
102
+ var timerId = setTimeout(function () {
103
+ console.log('clear web-preloadsdk web app', url);
104
+ _this.clearPreloadContainer(taskId);
105
+ }, MAX_CLEAR_TIME);
106
+ this.clearTimerIdMapping[taskId] = timerId;
107
+ }
108
+ }, {
109
+ key: "clearPreloadContainer",
110
+ value: function clearPreloadContainer(taskId) {
111
+ var timerId = this.clearTimerIdMapping[taskId];
112
+ if (timerId) {
113
+ clearTimeout(timerId);
114
+ }
115
+ var container = document.getElementById(taskId);
116
+ if (container) {
117
+ document.body.removeChild(container);
118
+ }
119
+ }
120
+ }, {
121
+ key: "showLoading",
122
+ value: function showLoading(container, displayInfo) {
123
+ if (this.customizedLoadingListener) {
124
+ this.customizedLoadingListener('SDK_START_OF_LOADING');
125
+ return;
126
+ }
127
+ if (displayInfo.type === DisplayTypeEnum.inline) {
128
+ addInlineLoading(container, displayInfo.platform);
129
+ } else {
130
+ var mockup = document.getElementById(MOCKUP_ID);
131
+ if (mockup) mockup.style.display = 'block';
132
+ addPopupLoading();
133
+ }
134
+ }
135
+ }, {
136
+ key: "dismissLoading",
137
+ value: function dismissLoading() {
138
+ var _document$getElementB2;
139
+ var isKeepMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
140
+ if (this.customizedLoadingListener) {
141
+ this.customizedLoadingListener('SDK_END_OF_LOADING');
142
+ return;
143
+ }
144
+ var mockup = document.getElementById(MOCKUP_ID);
145
+ if (mockup) {
146
+ mockup.style.background = 'rgb(0, 0, 0, 0.6)';
147
+ mockup.style.display = isKeepMockup ? 'block' : 'none';
148
+ }
149
+ (_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
150
+ }
151
+ }, {
152
+ key: "customizeLoading",
153
+ value: function customizeLoading(listener) {
154
+ this.customizedLoadingListener = listener;
155
+ }
156
+ }, {
157
+ key: "startHideAnim",
158
+ value: function startHideAnim() {
159
+ var _this$displayInfo;
160
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
161
+ if (this.webApp) this.webApp.style.height = container.style.height;
162
+ if (container && (_this$displayInfo = this.displayInfo) !== null && _this$displayInfo !== void 0 && _this$displayInfo.platform) {
163
+ // size变化动画取消
164
+ container.style.transition = '';
165
+ container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform));
166
+ container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform, "-animation"));
167
+ container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.displayInfo.platform));
168
+ }
169
+ }
170
+ }, {
171
+ key: "addCapabilityToEventCenter",
172
+ value: function addCapabilityToEventCenter() {
173
+ var _this2 = this;
174
+ this.eventCenter.listen(EVENT.dismissLoading.name, function () {
175
+ _this2.dismissLoading();
176
+ });
177
+ this.eventCenter.listen(EVENT.getUserAgentFromSdk.name, function (data, payload) {
178
+ var _payload$context;
179
+ _this2.eventCenter.dispatchToApp({
180
+ event: 'appEventCallback',
181
+ eventCallbackId: (_payload$context = payload.context) === null || _payload$context === void 0 ? void 0 : _payload$context.eventCallbackId,
182
+ data: {
183
+ userAgent: window.navigator.userAgent
184
+ }
185
+ });
186
+ });
187
+ this.eventCenter.listen(EVENT.popupWindow.name, function (data) {
188
+ var _this2$displayInfo;
189
+ if (data.paymentElementOldModel) return;
190
+ _this2.popupManager.popup(_objectSpread({
191
+ platform: (_this2$displayInfo = _this2.displayInfo) === null || _this2$displayInfo === void 0 ? void 0 : _this2$displayInfo.platform
192
+ }, data)).catch(function (error) {
193
+ _this2.logService.logError({
194
+ title: (error === null || error === void 0 ? void 0 : error.title) || 'sdk_error_create_pop_up'
195
+ }, error);
196
+ _this2.eventCenter.emit(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
197
+ });
198
+ });
199
+ this.eventCenter.listen(EVENT.popWindow.name, function () {
200
+ _this2.popupManager.pop();
201
+ });
202
+ this.eventCenter.listen(EVENT.sizeChanged.name, function (data) {
203
+ _this2.handleSizeChanged(_objectSpread({}, data));
204
+ });
205
+ this.eventCenter.listen(EVENT.showCloseButton.name, function () {
206
+ _this2.changeCloseBtnVisibility(true);
207
+ });
208
+ this.eventCenter.listen(EVENT.hideCloseButton.name, function () {
209
+ _this2.changeCloseBtnVisibility(false);
210
+ });
211
+ this.eventCenter.listen(EVENT.setMaskCloseButton.name, function (data) {
212
+ _this2.handleMaskCloseBtnShow(data);
213
+ });
214
+ this.eventCenter.listen(EVENT.appHeartBeat.name, function () {
215
+ _this2.handleAppHeartBeat();
216
+ });
217
+ }
218
+ }, {
219
+ key: "addCapabilityToApiBusManager",
220
+ value: function addCapabilityToApiBusManager() {}
221
+ }, {
222
+ key: "updateMaskCloseBtn",
223
+ value: function updateMaskCloseBtn(data) {
224
+ var maskCloseBtn = document.getElementById("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID));
225
+ if (maskCloseBtn) {
226
+ if (this.displayInfo.platform === 'desktop') {
227
+ var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
228
+ var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
229
+ maskCloseBtn.style.top = "".concat((windowHeight - data.height) / 2 - 42, "px");
230
+ maskCloseBtn.style.right = "".concat((windowWidth - data.width) / 2 + 18, "px");
231
+ } else {
232
+ maskCloseBtn.style.bottom = "".concat(data.height + 2, "px");
233
+ }
234
+ }
235
+ }
236
+ }, {
237
+ key: "handleSizeChanged",
238
+ value: function handleSizeChanged(data) {
239
+ if (!this.webApp || !this.displayInfo) {
240
+ return;
241
+ }
242
+ var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
243
+ if ((data === null || data === void 0 ? void 0 : data.height) <= 1 || data.height === parseInt(cashier.style.height)) return;
244
+ cashier.style.height = "".concat(data.height, "px");
245
+ this.webApp.style.opacity = '1';
246
+ if (this.displayInfo.type === DisplayTypeEnum.popup) {
247
+ if (this.displayInfo.platform === 'desktop') {
248
+ if (data.width) cashier.style.width = "".concat(data.width, "px");
249
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform, "-animation"));
250
+ this.webApp.style.height = "".concat(data.height, "px");
251
+ }
252
+ if (this.displayInfo.platform === 'mobile') {
253
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform, "-animation"));
254
+ var animationStyleId = "".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform, "-animation-style");
255
+ var animationStyle = document.getElementById(animationStyleId);
256
+ if (animationStyle) animationStyle === null || animationStyle === void 0 || animationStyle.remove();
257
+
258
+ // 此style用于弹窗出现和高度变化时动画,动画不同,属性不同
259
+ this.webApp.style.height = parseInt(this.webApp.style.height) > 0 ? '100%' : "".concat(data.height, "px");
260
+ startSizeChangeAnim(cashier, data.height, animationStyleId);
261
+ }
262
+ // 关闭loading,保留蒙层
263
+ this.dismissLoading();
264
+ // 更新弹窗关闭按钮位置
265
+ this.updateMaskCloseBtn(data);
266
+ }
267
+ if (this.displayInfo.type === DisplayTypeEnum.inline) {
268
+ var _document$getElementB3;
269
+ (_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
270
+ this.webApp.style.height = "".concat(data.height, "px");
271
+ }
272
+ }
273
+ }, {
274
+ key: "handleAppHeartBeat",
275
+ value: function handleAppHeartBeat() {
276
+ var _this3 = this;
277
+ try {
278
+ if (!this._webAppHeartBeatTimeoutFn) {
279
+ this._webAppHeartBeatTimeoutFn = function () {
280
+ if (_this3.webApp && _this3.displayInfo) {
281
+ _this3.logService.logError({
282
+ title: 'sdk_error_appHeartBeatTimeout'
283
+ });
284
+ }
285
+ };
286
+ }
287
+ if (window._webAppHeartBeatTimeoutId) {
288
+ clearTimeout(window._webAppHeartBeatTimeoutId);
289
+ window._webAppHeartBeatTimeoutId = null;
290
+ }
291
+ if (this._webAppHeartBeatTimeoutFn) {
292
+ window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
293
+ }
294
+ setTimeout(function () {
295
+ if (_this3.webApp && _this3.displayInfo) {
296
+ _this3.eventCenter.dispatchToApp({
297
+ event: 'sdkHeartBeat',
298
+ data: {}
299
+ });
300
+ }
301
+ }, TIME_DELAY_SEND_HEART_BEAT);
302
+ } catch (error) {
303
+ this.logService.logError({
304
+ title: 'sdk_error_handleAppHeartBeat'
305
+ }, {
306
+ errorMessage: error.message
307
+ });
308
+ }
309
+ }
310
+ }, {
311
+ key: "changeCloseBtnVisibility",
312
+ value: function changeCloseBtnVisibility(isShow) {
313
+ var closeBlock = document.getElementById(COMPONENT_CLOSE_BLOCK_ID);
314
+ if (isShow) {
315
+ closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
316
+ } else if (isShow === false) {
317
+ closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
318
+ }
319
+ }
320
+ }, {
321
+ key: "handleMaskCloseBtnShow",
322
+ value: function handleMaskCloseBtnShow(data) {
323
+ var closeBlock = document.getElementById(COMPONENT_CLOSE_MASK_BLOCK_ID);
324
+ if ((data === null || data === void 0 ? void 0 : data.status) === 'show') {
325
+ closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-hidden"));
326
+ } else {
327
+ closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-hidden"));
328
+ }
329
+ }
330
+ }]);
331
+ return ContainerService;
332
+ }();
@@ -0,0 +1,17 @@
1
+ import { PlatformEnum } from '../../../types';
2
+ /**
3
+ * @author 谦彧 <zhangmian.zm@alipay.com>
4
+ * @date 2024/9/22
5
+ */
6
+ export declare class PopupManager {
7
+ private popupUrlQuery;
8
+ private popupApp;
9
+ setPopupUrlQuery(queryParams: string): void;
10
+ popup(data: {
11
+ url: string;
12
+ widthPadding: number;
13
+ heightPadding: number;
14
+ platform: PlatformEnum;
15
+ }): Promise<void>;
16
+ pop(): void;
17
+ }