@alipay/ams-checkout 1.23.0 → 1.24.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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +10 -10
- package/esm/constant/index.d.ts +6 -0
- package/esm/constant/index.js +8 -0
- package/esm/core/bus/ability/globalData.d.ts +10 -0
- package/esm/core/bus/ability/globalData.js +89 -0
- package/esm/core/bus/ability/request.d.ts +10 -0
- package/esm/core/bus/ability/request.js +151 -0
- package/esm/core/bus/interface.d.ts +12 -0
- package/esm/core/bus/interface.js +16 -2
- package/esm/core/component/address.d.ts +2 -2
- package/esm/core/component/appPreloadProcessing.js +2 -0
- package/esm/core/component/ckp/index.d.ts +3 -3
- package/esm/core/component/ckp/index.js +6 -5
- package/esm/core/component/element/components/address.d.ts +19 -0
- package/esm/core/component/element/components/address.js +68 -0
- package/esm/core/component/element/components/auth.d.ts +17 -0
- package/esm/core/component/element/components/auth.js +60 -0
- package/esm/core/component/element/components/payment.d.ts +19 -0
- package/esm/core/component/element/components/payment.js +74 -0
- package/esm/core/component/element/index.d.ts +47 -0
- package/esm/core/component/element/index.js +816 -0
- package/esm/core/component/element/mock.d.ts +4 -0
- package/esm/core/component/element/mock.js +491 -0
- package/esm/core/component/element/type.d.ts +184 -0
- package/esm/core/component/element/type.js +35 -0
- package/esm/core/component/element/utils.d.ts +13 -0
- package/esm/core/component/element/utils.js +6 -0
- package/esm/core/component/index.d.ts +5 -5
- package/esm/core/component/index.js +20 -16
- package/esm/core/drop-in/index.d.ts +2 -2
- package/esm/core/drop-in/index.js +2 -2
- package/esm/core/instance/index.d.ts +5 -5
- package/esm/core/instance/index.js +11 -10
- package/esm/foundation/core/index.d.ts +26 -0
- package/esm/foundation/core/index.js +301 -0
- package/esm/foundation/index.d.ts +72 -0
- package/esm/foundation/index.js +42 -0
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +15 -0
- package/esm/foundation/product-processor/easysafepay/deps.js +9 -0
- package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
- package/esm/foundation/product-processor/easysafepay/index.js +536 -0
- package/esm/foundation/service/container/index.d.ts +28 -0
- package/esm/foundation/service/container/index.js +256 -0
- package/esm/foundation/service/container/popup.d.ts +17 -0
- package/esm/foundation/service/container/popup.js +103 -0
- package/esm/foundation/service/container/utils.d.ts +7 -0
- package/esm/foundation/service/container/utils.js +48 -0
- package/esm/foundation/service/event-bus/ability/callback.d.ts +9 -0
- package/esm/foundation/service/event-bus/ability/callback.js +55 -0
- package/esm/foundation/service/event-bus/ability/globalData.d.ts +10 -0
- package/esm/foundation/service/event-bus/ability/globalData.js +89 -0
- package/esm/foundation/service/event-bus/ability/request.d.ts +10 -0
- package/esm/foundation/service/event-bus/ability/request.js +151 -0
- package/esm/foundation/service/event-bus/ability/security.d.ts +12 -0
- package/esm/foundation/service/event-bus/ability/security.js +151 -0
- package/esm/foundation/service/event-bus/ability/tracker.d.ts +9 -0
- package/esm/foundation/service/event-bus/ability/tracker.js +80 -0
- package/esm/foundation/service/event-bus/busManager.d.ts +127 -0
- package/esm/foundation/service/event-bus/busManager.js +398 -0
- package/esm/foundation/service/event-bus/index.d.ts +20 -0
- package/esm/foundation/service/event-bus/index.js +88 -0
- package/esm/foundation/service/event-center.d.ts +75 -0
- package/esm/foundation/service/event-center.js +244 -0
- package/esm/foundation/service/global-data/index.d.ts +11 -0
- package/esm/foundation/service/global-data/index.js +69 -0
- package/esm/foundation/service/index.d.ts +19 -0
- package/esm/foundation/service/index.js +82 -0
- package/esm/foundation/service/log/index.d.ts +43 -0
- package/esm/foundation/service/log/index.js +235 -0
- package/esm/foundation/service/log/types.d.ts +32 -0
- package/esm/foundation/service/log/types.js +1 -0
- package/esm/foundation/service/requester/deps.d.ts +17 -0
- package/esm/foundation/service/requester/deps.js +11 -0
- package/esm/foundation/service/requester/requester.d.ts +22 -0
- package/esm/foundation/service/requester/requester.js +211 -0
- package/esm/foundation/service/security/index.d.ts +26 -0
- package/esm/foundation/service/security/index.js +216 -0
- package/esm/{util → foundation/service/security}/security.d.ts +2 -2
- package/esm/{util → foundation/service/security}/security.js +3 -3
- package/esm/foundation/types/index.d.ts +4 -0
- package/esm/foundation/types/index.js +4 -0
- package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
- package/esm/foundation/utils/gray_scale_utils.js +40 -0
- package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
- package/esm/foundation/utils/payment_context_utils.js +57 -0
- package/esm/foundation/utils/redirect_utils.d.ts +6 -0
- package/esm/foundation/utils/redirect_utils.js +99 -0
- package/esm/foundation/utils/system_events.d.ts +4 -0
- package/esm/foundation/utils/system_events.js +71 -0
- package/esm/foundation/utils/web_app_url_utils.d.ts +37 -0
- package/esm/foundation/utils/web_app_url_utils.js +97 -0
- package/esm/index.d.ts +16 -10
- package/esm/index.js +70 -59
- package/esm/plugin/applepay/component.js +3 -3
- package/esm/plugin/applepay/service.d.ts +2 -2
- package/esm/plugin/applepay/service.js +2 -2
- package/esm/plugin/component/cashierApp.d.ts +7 -5
- package/esm/plugin/component/cashierApp.js +16 -8
- package/esm/plugin/component/channel.d.ts +4 -4
- package/esm/plugin/component/component.inline.style.d.ts +4 -4
- package/esm/plugin/component/component.inline.style.js +10 -7
- package/esm/plugin/component/component.popup.style.d.ts +15 -6
- package/esm/plugin/component/component.popup.style.js +33 -15
- package/esm/plugin/component/index.d.ts +8 -7
- package/esm/plugin/component/index.js +153 -98
- package/esm/plugin/const.js +5 -5
- package/esm/plugin/drop-in/index.d.ts +5 -5
- package/esm/plugin/drop-in/index.js +7 -7
- package/esm/plugin/payment-element/utils.d.ts +1 -1
- package/esm/plugin/payment-element/utils.js +2 -1
- package/esm/plugin/type.d.ts +4 -4
- package/esm/service/element.d.ts +4 -0
- package/esm/service/element.js +51 -0
- package/esm/service/index.d.ts +1 -0
- package/esm/service/index.js +2 -0
- package/esm/types/index.d.ts +240 -38
- package/esm/types/index.js +103 -59
- package/esm/util/createIframeNode.d.ts +2 -2
- package/esm/util/createIframeNode.js +3 -3
- package/esm/util/index.d.ts +1 -1
- package/esm/util/index.js +3 -4
- package/package.json +2 -1
@@ -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 "../../../foundation/product-processor/easysafepay/deps";
|
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,75 @@
|
|
1
|
+
import { EventPayload, EventPayloadContext } from '../../types';
|
2
|
+
import { Service } from '../index';
|
3
|
+
/**
|
4
|
+
* @author 江跃 <jiangbin.gjb@antgroup.com>
|
5
|
+
* @date 2024/9/17
|
6
|
+
*/
|
7
|
+
export declare class EventCenter implements Service {
|
8
|
+
private events;
|
9
|
+
private iframes;
|
10
|
+
constructor();
|
11
|
+
/**
|
12
|
+
* Initializes the event center
|
13
|
+
*/
|
14
|
+
init(): void;
|
15
|
+
/**
|
16
|
+
* Cleans up event listeners when the event center is destroyed.
|
17
|
+
*/
|
18
|
+
destroy(): void;
|
19
|
+
/**
|
20
|
+
* Placeholder for future update logic.
|
21
|
+
*/
|
22
|
+
update(): void;
|
23
|
+
/**
|
24
|
+
* Sets the iframe container and its domain.
|
25
|
+
* @param iframe - The HTMLIFrameElement that serves as the container.
|
26
|
+
* @param domain - The domain of the app.
|
27
|
+
*/
|
28
|
+
addIFrame(iframe: HTMLIFrameElement): void;
|
29
|
+
removeIFrame(iframe: HTMLIFrameElement): void;
|
30
|
+
/**
|
31
|
+
* Handles messages received from the app.
|
32
|
+
* @param e - The message event.
|
33
|
+
*/
|
34
|
+
private handleAppMessage;
|
35
|
+
/**
|
36
|
+
* Processes the application message and emits the associated event.
|
37
|
+
* @param data - Parsed EventPayload from the app.
|
38
|
+
*/
|
39
|
+
private _handleAppMessage;
|
40
|
+
/**
|
41
|
+
* Listens to an event by adding a callback function.
|
42
|
+
* @param name - The name of the event to listen for.
|
43
|
+
* @param func - The callback function to execute when the event is emitted.
|
44
|
+
*/
|
45
|
+
listen(name: string, func: IListener): void;
|
46
|
+
/**
|
47
|
+
* Unsubscribes from an event. If a function is provided, only that function is removed.
|
48
|
+
* @param name - The name of the event to unlisten to.
|
49
|
+
* @param func - The optional callback function to remove.
|
50
|
+
*/
|
51
|
+
unlisten(name: string, func?: IListener): void;
|
52
|
+
/**
|
53
|
+
* Emits an event, executing all associated callback functions.
|
54
|
+
* @param name - The name of the event to emit.
|
55
|
+
* @param data - The event data to pass to the event listeners.
|
56
|
+
*/
|
57
|
+
emit(name: string, data: any, eventPayload?: EventPayload): void;
|
58
|
+
/**
|
59
|
+
* Registers a callback for an event and immediately dispatches the event to the app.
|
60
|
+
* @param payloadContext - The context containing event information and callback ID.
|
61
|
+
* @param func - The callback function to execute when the event is emitted.
|
62
|
+
*/
|
63
|
+
emitAndListen(payloadContext: EventPayloadContext, func: IListener): void;
|
64
|
+
queryParse(url?: string): Record<string, any>;
|
65
|
+
/**
|
66
|
+
* Dispatches the event payload to the app via postMessage.
|
67
|
+
* @param payloadContext - The context containing event to be dispatched.
|
68
|
+
*/
|
69
|
+
dispatchToApp(payloadContext: EventPayloadContext): void;
|
70
|
+
isExist(name: string): boolean;
|
71
|
+
}
|
72
|
+
interface IListener {
|
73
|
+
(data: any, eventPayload?: EventPayload): void;
|
74
|
+
}
|
75
|
+
export {};
|