@alipay/ams-checkout 1.23.0 → 1.25.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 (128) 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 +23 -0
  7. package/esm/component/component.popup.style.js +190 -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 +7 -7
  11. package/esm/config/index.js +10 -10
  12. package/esm/constant/index.d.ts +9 -5
  13. package/esm/constant/index.js +12 -78
  14. package/esm/core/component/ckp/index.js +6 -5
  15. package/esm/core/component/element/components/address.d.ts +19 -0
  16. package/esm/core/component/element/components/address.js +68 -0
  17. package/esm/core/component/element/components/auth.d.ts +17 -0
  18. package/esm/core/component/element/components/auth.js +60 -0
  19. package/esm/core/component/element/components/payment.d.ts +19 -0
  20. package/esm/core/component/element/components/payment.js +74 -0
  21. package/esm/core/component/element/index.d.ts +47 -0
  22. package/esm/core/component/element/index.js +816 -0
  23. package/esm/core/component/element/mock.d.ts +4 -0
  24. package/esm/core/component/element/mock.js +491 -0
  25. package/esm/core/component/element/type.d.ts +190 -0
  26. package/esm/core/component/element/type.js +35 -0
  27. package/esm/core/component/element/utils.d.ts +13 -0
  28. package/esm/core/component/element/utils.js +6 -0
  29. package/esm/core/component/index.d.ts +4 -4
  30. package/esm/core/component/index.js +14 -14
  31. package/esm/core/drop-in/index.js +2 -2
  32. package/esm/core/instance/index.js +9 -9
  33. package/esm/foundation/core/index.d.ts +26 -0
  34. package/esm/foundation/core/index.js +366 -0
  35. package/esm/foundation/index.d.ts +75 -0
  36. package/esm/foundation/index.js +42 -0
  37. package/esm/foundation/product-processor/easysafepay/deps.d.ts +18 -0
  38. package/esm/foundation/product-processor/easysafepay/deps.js +12 -0
  39. package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
  40. package/esm/foundation/product-processor/easysafepay/index.js +463 -0
  41. package/esm/foundation/service/api-bus/ability/callback.d.ts +9 -0
  42. package/esm/foundation/service/api-bus/ability/callback.js +55 -0
  43. package/esm/foundation/service/api-bus/ability/globalData.d.ts +10 -0
  44. package/esm/foundation/service/api-bus/ability/globalData.js +89 -0
  45. package/esm/foundation/service/api-bus/ability/request.d.ts +10 -0
  46. package/esm/foundation/service/api-bus/ability/request.js +151 -0
  47. package/esm/foundation/service/api-bus/ability/security.d.ts +12 -0
  48. package/esm/foundation/service/api-bus/ability/security.js +161 -0
  49. package/esm/foundation/service/api-bus/ability/tracker.d.ts +9 -0
  50. package/esm/foundation/service/api-bus/ability/tracker.js +80 -0
  51. package/esm/foundation/service/api-bus/busManager.d.ts +127 -0
  52. package/esm/foundation/service/api-bus/busManager.js +398 -0
  53. package/esm/foundation/service/api-bus/index.d.ts +20 -0
  54. package/esm/foundation/service/api-bus/index.js +88 -0
  55. package/esm/foundation/service/api-bus/interface.d.ts +48 -0
  56. package/esm/foundation/service/api-bus/interface.js +54 -0
  57. package/esm/foundation/service/container/index.d.ts +30 -0
  58. package/esm/foundation/service/container/index.js +298 -0
  59. package/esm/foundation/service/container/popup.d.ts +17 -0
  60. package/esm/foundation/service/container/popup.js +103 -0
  61. package/esm/foundation/service/container/utils.d.ts +7 -0
  62. package/esm/foundation/service/container/utils.js +48 -0
  63. package/esm/foundation/service/event-center.d.ts +76 -0
  64. package/esm/foundation/service/event-center.js +243 -0
  65. package/esm/foundation/service/global-data/index.d.ts +11 -0
  66. package/esm/foundation/service/global-data/index.js +68 -0
  67. package/esm/foundation/service/index.d.ts +19 -0
  68. package/esm/foundation/service/index.js +82 -0
  69. package/esm/foundation/service/log/index.d.ts +43 -0
  70. package/esm/foundation/service/log/index.js +235 -0
  71. package/esm/foundation/service/log/types.d.ts +32 -0
  72. package/esm/foundation/service/log/types.js +1 -0
  73. package/esm/foundation/service/requester/deps.d.ts +17 -0
  74. package/esm/foundation/service/requester/deps.js +11 -0
  75. package/esm/foundation/service/requester/requester.d.ts +22 -0
  76. package/esm/foundation/service/requester/requester.js +214 -0
  77. package/esm/foundation/service/security/index.d.ts +28 -0
  78. package/esm/foundation/service/security/index.js +286 -0
  79. package/esm/foundation/service/security/security.d.ts +33 -0
  80. package/esm/foundation/service/security/security.js +182 -0
  81. package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
  82. package/esm/foundation/utils/gray_scale_utils.js +40 -0
  83. package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
  84. package/esm/foundation/utils/payment_context_utils.js +57 -0
  85. package/esm/foundation/utils/payment_product_utils.d.ts +13 -0
  86. package/esm/foundation/utils/payment_product_utils.js +38 -0
  87. package/esm/foundation/utils/redirect_utils.d.ts +11 -0
  88. package/esm/foundation/utils/redirect_utils.js +263 -0
  89. package/esm/foundation/utils/system_events.d.ts +4 -0
  90. package/esm/foundation/utils/system_events.js +66 -0
  91. package/esm/foundation/utils/web_app_url_utils.d.ts +46 -0
  92. package/esm/foundation/utils/web_app_url_utils.js +112 -0
  93. package/esm/index.d.ts +12 -6
  94. package/esm/index.js +75 -64
  95. package/esm/plugin/applepay/component.js +3 -3
  96. package/esm/plugin/applepay/service.d.ts +2 -2
  97. package/esm/plugin/applepay/service.js +2 -2
  98. package/esm/plugin/component/cashierApp.d.ts +7 -5
  99. package/esm/plugin/component/cashierApp.js +15 -8
  100. package/esm/plugin/component/channel.d.ts +4 -4
  101. package/esm/plugin/component/component.inline.style.d.ts +4 -4
  102. package/esm/plugin/component/component.inline.style.js +10 -8
  103. package/esm/plugin/component/component.popup.style.d.ts +6 -6
  104. package/esm/plugin/component/component.popup.style.js +6 -6
  105. package/esm/plugin/component/index.d.ts +8 -7
  106. package/esm/plugin/component/index.js +160 -103
  107. package/esm/plugin/const.js +5 -5
  108. package/esm/plugin/drop-in/index.d.ts +5 -5
  109. package/esm/plugin/drop-in/index.js +7 -7
  110. package/esm/plugin/type.d.ts +3 -3
  111. package/esm/service/element.d.ts +4 -0
  112. package/esm/service/element.js +51 -0
  113. package/esm/service/index.d.ts +1 -0
  114. package/esm/service/index.js +2 -0
  115. package/esm/types/index.d.ts +247 -39
  116. package/esm/types/index.js +109 -59
  117. package/esm/util/createIframeNode.d.ts +2 -2
  118. package/esm/util/createIframeNode.js +3 -3
  119. package/esm/util/getBackScheme.js +95 -3
  120. package/esm/util/security.d.ts +2 -2
  121. package/esm/util/security.js +2 -2
  122. package/package.json +2 -1
  123. package/esm/util/ua/index.d.ts +0 -2
  124. package/esm/util/ua/index.js +0 -2
  125. package/esm/util/ua/isAndroid.d.ts +0 -4
  126. package/esm/util/ua/isAndroid.js +0 -7
  127. package/esm/util/ua/isIOS.d.ts +0 -4
  128. package/esm/util/ua/isIOS.js +0 -7
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Bus 埋点内容定义
3
+ */
4
+ export declare enum BusLogEventEnum {
5
+ /**
6
+ * 发送消息
7
+ * action:string
8
+ */
9
+ sdk_event_busPublishMessage = "sdk_event_busPublishMessage",
10
+ /**
11
+ * 发送消息时,返回事件结果(Web)
12
+ * action:string
13
+ */
14
+ sdk_event_busPublishCallback = "sdk_event_busPublishCallback",
15
+ /**
16
+ * 查询是否订阅
17
+ * action:string
18
+ * sub: bool
19
+ */
20
+ sdk_event_busIsSubscribe = "sdk_event_busIsSubscribe",
21
+ /**
22
+ * 订阅协议
23
+ * actions: string[] , 用逗号拼接
24
+ */
25
+ sdk_event_busSubscribe = "sdk_event_busSubscribe",
26
+ /**
27
+ * 退订协议
28
+ * actions: string[] , 用逗号拼接
29
+ */
30
+ sdk_event_busUnsubscribe = "sdk_event_busUnsubscribe",
31
+ /**
32
+ * 清除缓存(Web/Android)
33
+ */
34
+ sdk_event_busClear = "sdk_event_busClear",
35
+ /**
36
+ * 添加拦截器(Web/Android)
37
+ */
38
+ sdk_event_busAddInterceptor = "sdk_event_busAddInterceptor",
39
+ /**
40
+ * 发送消息时,对应aciton未订阅
41
+ */
42
+ sdk_error_busPublishUnsubscribeError = "sdk_error_busPublishUnsubscribeError",
43
+ /**
44
+ * 发送消息时异常
45
+ */
46
+ sdk_error_busPublishError = "sdk_error_busPublishError",
47
+ /**
48
+ * 发送消息无结果(Web)
49
+ */
50
+ sdk_error_busPublishNoResult = "sdk_error_busPublishNoResult"
51
+ }
52
+ /**
53
+ * 扩展协议可序列化的消息定义
54
+ */
55
+ export declare class BusMessage {
56
+ private action;
57
+ private data;
58
+ private jsonData;
59
+ constructor(action: string, data?: string);
60
+ getAction(): string;
61
+ getData(): string;
62
+ isJSONData(): boolean;
63
+ getJSONObject(): any;
64
+ private parseJSONData;
65
+ result(result?: any): BusMessage;
66
+ }
67
+ export type OnBusCallback = (message: BusMessage) => void;
68
+ /**
69
+ * 扩展总线可选的Context参数,在Web端用于实时回调
70
+ */
71
+ export declare class BusContext {
72
+ private callback;
73
+ constructor(callback: OnBusCallback);
74
+ onCallBack(message: BusMessage): void;
75
+ }
76
+ /**
77
+ * 扩展能力的能力定义,基于此协议实现扩展能力
78
+ */
79
+ export declare abstract class BusSubscriber {
80
+ abstract actionNames(): string[];
81
+ abstract onMessage(context: BusContext, message: BusMessage): void;
82
+ }
83
+ /**
84
+ * 拦截器,可增加扩展性
85
+ */
86
+ export interface BusInterceptor {
87
+ /**
88
+ * 未订阅场景拦截
89
+ * @param actionName
90
+ */
91
+ onUnsubscribedAction?(actionName: string): boolean;
92
+ /**
93
+ * 分发消息场景处理异常
94
+ * @param message
95
+ */
96
+ onPublishException?(message: BusMessage, e: any): void;
97
+ }
98
+ /**
99
+ * 事件总线入口,支持的关系为:
100
+ * 发送者 和 接收者的关系: 一对一,大多数场景,支持callback
101
+ * 发送者 和 接收者的关系: 多对一, 设计上多一对,但是同一时间点,只会一个发送者,支持callback
102
+ * 发送者 和 接收者的关系: 一对多,可能有,埋点多重上报?不需要callback,业务场景应该是一个广播场景
103
+ */
104
+ export declare class BusManager {
105
+ private static interceptors;
106
+ private static subscribersMap;
107
+ private static TAG;
108
+ private static _logSplit;
109
+ private isDebug;
110
+ private instanceId;
111
+ private logger;
112
+ constructor(instanceId?: string);
113
+ debugTrace(enable: boolean): void;
114
+ private traceLog;
115
+ private traceError;
116
+ private static getInstanceActionName;
117
+ clear(): void;
118
+ addInterceptor(interceptor: BusInterceptor): void;
119
+ publishForResult(message: BusMessage, config?: {
120
+ timeoutMs?: number;
121
+ fallback?: any;
122
+ }): Promise<BusMessage>;
123
+ publish(message: BusMessage, callback?: OnBusCallback): void;
124
+ subscribe(subscriber: BusSubscriber): void;
125
+ unsubscribe(subscriber: BusSubscriber): void;
126
+ isSubscribed(actionName: string): boolean;
127
+ }
@@ -0,0 +1,398 @@
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ 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; }
6
+ 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; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ 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; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ 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); }
13
+ import { ServiceProvider } from '..';
14
+ /**
15
+ * Bus 埋点内容定义
16
+ */
17
+ export var BusLogEventEnum = /*#__PURE__*/function (BusLogEventEnum) {
18
+ BusLogEventEnum["sdk_event_busPublishMessage"] = "sdk_event_busPublishMessage";
19
+ BusLogEventEnum["sdk_event_busPublishCallback"] = "sdk_event_busPublishCallback";
20
+ BusLogEventEnum["sdk_event_busIsSubscribe"] = "sdk_event_busIsSubscribe";
21
+ BusLogEventEnum["sdk_event_busSubscribe"] = "sdk_event_busSubscribe";
22
+ BusLogEventEnum["sdk_event_busUnsubscribe"] = "sdk_event_busUnsubscribe";
23
+ BusLogEventEnum["sdk_event_busClear"] = "sdk_event_busClear";
24
+ BusLogEventEnum["sdk_event_busAddInterceptor"] = "sdk_event_busAddInterceptor";
25
+ BusLogEventEnum["sdk_error_busPublishUnsubscribeError"] = "sdk_error_busPublishUnsubscribeError";
26
+ BusLogEventEnum["sdk_error_busPublishError"] = "sdk_error_busPublishError";
27
+ BusLogEventEnum["sdk_error_busPublishNoResult"] = "sdk_error_busPublishNoResult";
28
+ return BusLogEventEnum;
29
+ }({});
30
+
31
+ /**
32
+ * 扩展协议可序列化的消息定义
33
+ */
34
+ export var BusMessage = /*#__PURE__*/function () {
35
+ function BusMessage(action, data) {
36
+ _classCallCheck(this, BusMessage);
37
+ _defineProperty(this, "action", void 0);
38
+ _defineProperty(this, "data", void 0);
39
+ _defineProperty(this, "jsonData", null);
40
+ this.action = action;
41
+ this.data = data;
42
+ }
43
+ _createClass(BusMessage, [{
44
+ key: "getAction",
45
+ value: function getAction() {
46
+ return this.action;
47
+ }
48
+ }, {
49
+ key: "getData",
50
+ value: function getData() {
51
+ return this.data;
52
+ }
53
+ }, {
54
+ key: "isJSONData",
55
+ value: function isJSONData() {
56
+ this.parseJSONData();
57
+ return this.jsonData !== null;
58
+ }
59
+ }, {
60
+ key: "getJSONObject",
61
+ value: function getJSONObject() {
62
+ var _this$jsonData;
63
+ this.parseJSONData();
64
+ return (_this$jsonData = this.jsonData) !== null && _this$jsonData !== void 0 ? _this$jsonData : {};
65
+ }
66
+ }, {
67
+ key: "parseJSONData",
68
+ value: function parseJSONData() {
69
+ if (this.jsonData === null) {
70
+ try {
71
+ this.jsonData = JSON.parse(this.data);
72
+ } catch (e) {
73
+ // handle error if JSON parsing fails
74
+ this.jsonData = null;
75
+ }
76
+ }
77
+ }
78
+ }, {
79
+ key: "result",
80
+ value: function result(_result) {
81
+ return new BusMessage(this.action, JSON.stringify(_result));
82
+ }
83
+ }]);
84
+ return BusMessage;
85
+ }();
86
+ /**
87
+ * 扩展总线可选的Context参数,在Web端用于实时回调
88
+ */
89
+ export var BusContext = /*#__PURE__*/function () {
90
+ function BusContext(callback) {
91
+ _classCallCheck(this, BusContext);
92
+ _defineProperty(this, "callback", void 0);
93
+ this.callback = callback;
94
+ }
95
+ _createClass(BusContext, [{
96
+ key: "onCallBack",
97
+ value: function onCallBack(message) {
98
+ if (this.callback) {
99
+ this.callback(message);
100
+ }
101
+ }
102
+ }]);
103
+ return BusContext;
104
+ }();
105
+
106
+ /**
107
+ * 扩展能力的能力定义,基于此协议实现扩展能力
108
+ */
109
+ export var BusSubscriber = /*#__PURE__*/_createClass(function BusSubscriber() {
110
+ _classCallCheck(this, BusSubscriber);
111
+ });
112
+
113
+ /**
114
+ * 拦截器,可增加扩展性
115
+ */
116
+
117
+ /**
118
+ * 事件总线入口,支持的关系为:
119
+ * 发送者 和 接收者的关系: 一对一,大多数场景,支持callback
120
+ * 发送者 和 接收者的关系: 多对一, 设计上多一对,但是同一时间点,只会一个发送者,支持callback
121
+ * 发送者 和 接收者的关系: 一对多,可能有,埋点多重上报?不需要callback,业务场景应该是一个广播场景
122
+ */
123
+ export var BusManager = /*#__PURE__*/function () {
124
+ function BusManager() {
125
+ var instanceId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
126
+ _classCallCheck(this, BusManager);
127
+ // Instance Variable
128
+ _defineProperty(this, "isDebug", true);
129
+ _defineProperty(this, "instanceId", void 0);
130
+ _defineProperty(this, "logger", void 0);
131
+ this.instanceId = instanceId;
132
+ this.logger = ServiceProvider.getInstance(this.instanceId).getService('Log');
133
+ }
134
+ _createClass(BusManager, [{
135
+ key: "debugTrace",
136
+ value: function debugTrace(enable) {
137
+ this.isDebug = enable;
138
+ }
139
+ }, {
140
+ key: "traceLog",
141
+ value: function traceLog(title, optionalParams) {
142
+ var report = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
143
+ if (this.isDebug) {
144
+ console.log([BusManager.TAG, title].concat(JSON.stringify(optionalParams)).join(BusManager._logSplit));
145
+ }
146
+ if (report && this.logger) {
147
+ this.logger.logInfo({
148
+ title: title
149
+ }, _objectSpread({
150
+ biz: 'sdk'
151
+ }, optionalParams)).send();
152
+ }
153
+ }
154
+ }, {
155
+ key: "traceError",
156
+ value: function traceError(title, optionalParams) {
157
+ if (this.isDebug) {
158
+ console.error([BusManager.TAG, title].concat(JSON.stringify(optionalParams)).join(BusManager._logSplit));
159
+ }
160
+ if (this.logger) {
161
+ this.logger.logError({
162
+ title: title
163
+ }, _objectSpread({
164
+ biz: 'sdk'
165
+ }, optionalParams)).send();
166
+ }
167
+ }
168
+ }, {
169
+ key: "clear",
170
+ value: function clear() {
171
+ this.traceLog(BusLogEventEnum.sdk_event_busClear);
172
+ BusManager.interceptors.length = 0;
173
+ BusManager.subscribersMap.clear();
174
+ }
175
+ }, {
176
+ key: "addInterceptor",
177
+ value: function addInterceptor(interceptor) {
178
+ this.traceLog(BusLogEventEnum.sdk_event_busAddInterceptor);
179
+ if (!BusManager.interceptors.includes(interceptor)) {
180
+ BusManager.interceptors.push(interceptor);
181
+ }
182
+ }
183
+ }, {
184
+ key: "publishForResult",
185
+ value: function publishForResult(message, config) {
186
+ var _this = this;
187
+ var failed = true;
188
+ return new Promise(function (resolve, reject) {
189
+ var _config$timeoutMs;
190
+ _this.publish(message, function (result) {
191
+ failed = false;
192
+ resolve(result);
193
+ });
194
+ setTimeout(function () {
195
+ if (failed) {
196
+ _this.traceError(BusLogEventEnum.sdk_error_busPublishNoResult, {
197
+ action: message.getAction()
198
+ });
199
+ if ((config === null || config === void 0 ? void 0 : config.fallback) !== null) {
200
+ resolve(message.result(config === null || config === void 0 ? void 0 : config.fallback));
201
+ } else {
202
+ reject('publish timeout');
203
+ }
204
+ }
205
+ }, (_config$timeoutMs = config === null || config === void 0 ? void 0 : config.timeoutMs) !== null && _config$timeoutMs !== void 0 ? _config$timeoutMs : 2000);
206
+ });
207
+ }
208
+ }, {
209
+ key: "publish",
210
+ value: function publish(message, callback) {
211
+ var _this2 = this;
212
+ var _callBack = function _callBack(result) {
213
+ _this2.traceLog(BusLogEventEnum.sdk_event_busPublishCallback, {
214
+ action: message.getAction(),
215
+ instanceId: _this2.instanceId
216
+ });
217
+ if (callback) {
218
+ callback(result);
219
+ }
220
+ };
221
+ var context = new BusContext(_callBack);
222
+ var actionName = this.instanceId ? BusManager.getInstanceActionName(message.getAction(), this.instanceId) : message.getAction();
223
+ var subscribers = BusManager.subscribersMap.get(actionName);
224
+ this.traceLog(BusLogEventEnum.sdk_event_busPublishMessage, {
225
+ action: message.getAction(),
226
+ instanceId: this.instanceId
227
+ });
228
+ if (!subscribers && this.instanceId) {
229
+ // 如果没有找到特定实例的订阅者,尝试查找通用订阅者
230
+ subscribers = BusManager.subscribersMap.get(message.getAction());
231
+ }
232
+ if (subscribers) {
233
+ var _iterator = _createForOfIteratorHelper(subscribers),
234
+ _step;
235
+ try {
236
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
237
+ var subscriber = _step.value;
238
+ try {
239
+ subscriber.onMessage(context, message);
240
+ } catch (e) {
241
+ this.traceError(BusLogEventEnum.sdk_error_busPublishError, {
242
+ action: message.getAction(),
243
+ instanceId: this.instanceId,
244
+ error: e
245
+ });
246
+ var _iterator2 = _createForOfIteratorHelper(BusManager.interceptors),
247
+ _step2;
248
+ try {
249
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
250
+ var interceptor = _step2.value;
251
+ interceptor === null || interceptor === void 0 || interceptor.onPublishException(message, e);
252
+ }
253
+ } catch (err) {
254
+ _iterator2.e(err);
255
+ } finally {
256
+ _iterator2.f();
257
+ }
258
+ }
259
+ }
260
+ } catch (err) {
261
+ _iterator.e(err);
262
+ } finally {
263
+ _iterator.f();
264
+ }
265
+ } else {
266
+ var handle = false;
267
+ var _iterator3 = _createForOfIteratorHelper(BusManager.interceptors),
268
+ _step3;
269
+ try {
270
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
271
+ var _interceptor = _step3.value;
272
+ handle = handle || (_interceptor === null || _interceptor === void 0 ? void 0 : _interceptor.onUnsubscribedAction(message.getAction()));
273
+ }
274
+ } catch (err) {
275
+ _iterator3.e(err);
276
+ } finally {
277
+ _iterator3.f();
278
+ }
279
+ if (handle) {
280
+ this.publish(message, callback); // Re-publish the message
281
+ } else {
282
+ this.traceError(BusLogEventEnum.sdk_error_busPublishUnsubscribeError, {
283
+ action: message.getAction(),
284
+ instanceId: this.instanceId
285
+ });
286
+ }
287
+ }
288
+ }
289
+ }, {
290
+ key: "subscribe",
291
+ value: function subscribe(subscriber) {
292
+ this.traceLog(BusLogEventEnum.sdk_event_busSubscribe, {
293
+ actions: subscriber.actionNames(),
294
+ instanceId: this.instanceId
295
+ });
296
+ var _iterator4 = _createForOfIteratorHelper(subscriber.actionNames()),
297
+ _step4;
298
+ try {
299
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
300
+ var _actionName = _step4.value;
301
+ var key = this.instanceId ? BusManager.getInstanceActionName(_actionName, this.instanceId) : _actionName;
302
+ if (!BusManager.subscribersMap.has(key)) {
303
+ BusManager.subscribersMap.set(key, []);
304
+ }
305
+ var subscribers = BusManager.subscribersMap.get(key);
306
+ if (subscribers && !subscribers.includes(subscriber)) {
307
+ subscribers.push(subscriber);
308
+ }
309
+ }
310
+ } catch (err) {
311
+ _iterator4.e(err);
312
+ } finally {
313
+ _iterator4.f();
314
+ }
315
+ }
316
+ }, {
317
+ key: "unsubscribe",
318
+ value: function unsubscribe(subscriber) {
319
+ this.traceLog(BusLogEventEnum.sdk_event_busUnsubscribe, {
320
+ actions: subscriber.actionNames(),
321
+ instanceId: this.instanceId
322
+ });
323
+ var _iterator5 = _createForOfIteratorHelper(subscriber.actionNames()),
324
+ _step5;
325
+ try {
326
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
327
+ var _actionName2 = _step5.value;
328
+ var key = this.instanceId ? BusManager.getInstanceActionName(_actionName2, this.instanceId) : _actionName2;
329
+ var subscribers = BusManager.subscribersMap.get(key);
330
+ if (subscribers) {
331
+ var index = subscribers.indexOf(subscriber);
332
+ if (index !== -1) {
333
+ subscribers.splice(index, 1);
334
+ }
335
+ if (subscribers.length === 0) {
336
+ BusManager.subscribersMap.delete(key);
337
+ }
338
+ }
339
+ }
340
+ } catch (err) {
341
+ _iterator5.e(err);
342
+ } finally {
343
+ _iterator5.f();
344
+ }
345
+ }
346
+ }, {
347
+ key: "isSubscribed",
348
+ value: function isSubscribed(actionName) {
349
+ var key = this.instanceId ? BusManager.getInstanceActionName(actionName, this.instanceId) : actionName;
350
+ var subscribers = BusManager.subscribersMap.get(key);
351
+ if (!subscribers && this.instanceId) {
352
+ // 如果没有找到特定实例的订阅者,检查是否有通用订阅者
353
+ subscribers = BusManager.subscribersMap.get(actionName);
354
+ }
355
+ if (subscribers && subscribers.length > 0) {
356
+ this.traceLog(BusLogEventEnum.sdk_event_busIsSubscribe, {
357
+ action: actionName,
358
+ instanceId: this.instanceId,
359
+ sub: true
360
+ });
361
+ return true;
362
+ }
363
+ var handle = false;
364
+ var _iterator6 = _createForOfIteratorHelper(BusManager.interceptors),
365
+ _step6;
366
+ try {
367
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
368
+ var interceptor = _step6.value;
369
+ handle = handle || interceptor.onUnsubscribedAction(actionName);
370
+ }
371
+ } catch (err) {
372
+ _iterator6.e(err);
373
+ } finally {
374
+ _iterator6.f();
375
+ }
376
+ if (handle) {
377
+ return BusManager.subscribersMap.has(key);
378
+ }
379
+ this.traceLog(BusLogEventEnum.sdk_event_busIsSubscribe, {
380
+ action: actionName,
381
+ instanceId: this.instanceId,
382
+ sub: false
383
+ });
384
+ return false;
385
+ }
386
+ }], [{
387
+ key: "getInstanceActionName",
388
+ value: function getInstanceActionName(actionName, instanceId) {
389
+ return "".concat(actionName, "@").concat(instanceId);
390
+ }
391
+ }]);
392
+ return BusManager;
393
+ }();
394
+ // Static Variable
395
+ _defineProperty(BusManager, "interceptors", []);
396
+ _defineProperty(BusManager, "subscribersMap", new Map());
397
+ _defineProperty(BusManager, "TAG", 'BusManager');
398
+ _defineProperty(BusManager, "_logSplit", ' , ');
@@ -0,0 +1,20 @@
1
+ import { Service } from '../../index';
2
+ import { IoptionsParams } from '../../../types';
3
+ import { LogService } from '../log';
4
+ import { BusMessage, BusSubscriber, OnBusCallback } from './busManager';
5
+ /**
6
+ * @author 谦彧 <zhangmian.zm@alipay.com>
7
+ * @date 2024/9/17
8
+ */
9
+ export declare class ApiBusManagerService implements Service {
10
+ protected logger: LogService;
11
+ protected instanceId: string;
12
+ private busManager;
13
+ init(initOptions: IoptionsParams, instanceId: string): void;
14
+ subscribe(subscriber: BusSubscriber): void;
15
+ unsubscribe(subscriber: BusSubscriber): void;
16
+ isSubscribed(actionName: string): boolean;
17
+ publish(message: BusMessage, callback?: OnBusCallback): void;
18
+ update(): void;
19
+ destroy(): void;
20
+ }
@@ -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
+ }