@alipay/ams-checkout 0.0.1726734012-dev.1 → 0.0.1726734012-dev.2
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/component/channel.d.ts +19 -0
- package/esm/component/channel.js +87 -0
- package/esm/component/component.inline.style.d.ts +10 -0
- package/esm/component/component.inline.style.js +121 -0
- package/esm/component/component.popup.style.d.ts +25 -0
- package/esm/component/component.popup.style.js +203 -0
- package/esm/component/popupWindow.style.d.ts +11 -0
- package/esm/component/popupWindow.style.js +121 -0
- package/esm/config/index.d.ts +11 -0
- package/esm/config/index.js +20 -1
- package/esm/constant/index.d.ts +25 -0
- package/esm/constant/index.js +28 -0
- package/esm/core/bus/index.d.ts +3 -3
- package/esm/core/bus/index.js +14 -14
- package/esm/core/component/address.d.ts +8 -0
- package/esm/core/component/address.js +72 -0
- package/esm/core/component/appPreloadProcessing.js +2 -2
- package/esm/core/component/ckp/index.js +12 -8
- 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 +817 -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 +191 -0
- package/esm/core/component/element/type.js +36 -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 +12 -7
- package/esm/core/component/index.js +132 -78
- package/esm/core/drop-in/index.js +2 -2
- package/esm/core/instance/index.d.ts +1 -0
- package/esm/core/instance/index.js +24 -11
- package/esm/foundation/core/index.d.ts +28 -0
- package/esm/foundation/core/index.js +396 -0
- package/esm/foundation/index.d.ts +75 -0
- package/esm/foundation/index.js +42 -0
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +18 -0
- package/esm/foundation/product-processor/easysafepay/deps.js +12 -0
- package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
- package/esm/foundation/product-processor/easysafepay/index.js +464 -0
- package/esm/foundation/service/api-bus/ability/callback.d.ts +9 -0
- package/esm/foundation/service/api-bus/ability/callback.js +55 -0
- package/esm/foundation/service/api-bus/ability/globalData.d.ts +10 -0
- package/esm/foundation/service/api-bus/ability/globalData.js +89 -0
- package/esm/foundation/service/api-bus/ability/request.d.ts +10 -0
- package/esm/foundation/service/api-bus/ability/request.js +151 -0
- package/esm/foundation/service/api-bus/ability/security.d.ts +12 -0
- package/esm/foundation/service/api-bus/ability/security.js +161 -0
- package/esm/foundation/service/api-bus/ability/tracker.d.ts +9 -0
- package/esm/foundation/service/api-bus/ability/tracker.js +80 -0
- package/esm/foundation/service/api-bus/busManager.d.ts +127 -0
- package/esm/foundation/service/api-bus/busManager.js +398 -0
- package/esm/foundation/service/api-bus/index.d.ts +20 -0
- package/esm/foundation/service/api-bus/index.js +88 -0
- package/esm/foundation/service/api-bus/interface.d.ts +48 -0
- package/esm/foundation/service/api-bus/interface.js +54 -0
- package/esm/foundation/service/container/index.d.ts +32 -0
- package/esm/foundation/service/container/index.js +330 -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-center.d.ts +82 -0
- package/esm/foundation/service/event-center.js +274 -0
- package/esm/foundation/service/global-data/index.d.ts +11 -0
- package/esm/foundation/service/global-data/index.js +68 -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 +250 -0
- package/esm/foundation/service/log/keys.d.ts +13 -0
- package/esm/foundation/service/log/keys.js +103 -0
- package/esm/foundation/service/log/processor.d.ts +9 -0
- package/esm/foundation/service/log/processor.js +148 -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 +217 -0
- package/esm/foundation/service/security/index.d.ts +28 -0
- package/esm/foundation/service/security/index.js +284 -0
- package/esm/foundation/service/security/security.d.ts +33 -0
- package/esm/foundation/service/security/security.js +182 -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/payment_product_utils.d.ts +13 -0
- package/esm/foundation/utils/payment_product_utils.js +38 -0
- package/esm/foundation/utils/redirect_utils.d.ts +11 -0
- package/esm/foundation/utils/redirect_utils.js +262 -0
- package/esm/foundation/utils/system_events.d.ts +4 -0
- package/esm/foundation/utils/system_events.js +66 -0
- package/esm/foundation/utils/web_app_url_utils.d.ts +46 -0
- package/esm/foundation/utils/web_app_url_utils.js +112 -0
- package/esm/index.d.ts +19 -12
- package/esm/index.js +110 -56
- package/esm/plugin/applepay/component.js +13 -11
- package/esm/plugin/applepay/index.js +10 -6
- package/esm/plugin/applepay/service.d.ts +2 -2
- package/esm/plugin/applepay/service.js +26 -18
- package/esm/plugin/component/cashierApp.d.ts +10 -8
- package/esm/plugin/component/cashierApp.js +48 -11
- package/esm/plugin/component/channel.d.ts +4 -3
- package/esm/plugin/component/channel.js +39 -2
- package/esm/plugin/component/component.inline.style.d.ts +9 -10
- package/esm/plugin/component/component.inline.style.js +93 -10
- package/esm/plugin/component/component.popup.style.d.ts +15 -6
- package/esm/plugin/component/component.popup.style.js +30 -7
- package/esm/plugin/component/index.d.ts +14 -8
- package/esm/plugin/component/index.js +383 -187
- package/esm/plugin/component/popupWindow.style.d.ts +5 -2
- package/esm/plugin/component/popupWindow.style.js +70 -14
- 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 +2 -0
- package/esm/plugin/payment-element/utils.js +6 -0
- package/esm/plugin/paypal/index.js +2 -1
- package/esm/plugin/type.d.ts +4 -3
- 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 +6 -2
- package/esm/types/index.d.ts +337 -40
- package/esm/types/index.js +119 -55
- package/esm/util/createIframeNode.d.ts +2 -2
- package/esm/util/createIframeNode.js +3 -3
- package/esm/util/getBackScheme.d.ts +5 -0
- package/esm/util/getBackScheme.js +133 -0
- package/esm/util/index.js +4 -8
- package/esm/util/logger.d.ts +3 -3
- package/esm/util/logger.js +49 -13
- package/esm/util/security.d.ts +3 -2
- package/esm/util/security.js +2 -2
- package/esm/util/spm-map.d.ts +172 -0
- package/esm/util/spm-map.js +172 -0
- package/package.json +3 -1
@@ -0,0 +1,80 @@
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
+
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); } }
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
8
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
9
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
10
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
11
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
12
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
13
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
14
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
15
|
+
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; }
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
17
|
+
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); }
|
18
|
+
import { BusSubscriber } from "../busManager";
|
19
|
+
import { TrackerActionEnum } from "../interface";
|
20
|
+
import { ServiceProvider } from "../../../../foundation/service";
|
21
|
+
export var TrackerBusSubscriber = /*#__PURE__*/function (_BusSubscriber) {
|
22
|
+
_inherits(TrackerBusSubscriber, _BusSubscriber);
|
23
|
+
var _super = _createSuper(TrackerBusSubscriber);
|
24
|
+
function TrackerBusSubscriber(instanceId) {
|
25
|
+
var _this;
|
26
|
+
_classCallCheck(this, TrackerBusSubscriber);
|
27
|
+
_this = _super.call(this);
|
28
|
+
_defineProperty(_assertThisInitialized(_this), "instanceId", void 0);
|
29
|
+
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
30
|
+
_this.instanceId = instanceId;
|
31
|
+
_this.logger = ServiceProvider.getInstance(_this.instanceId).getService('Log');
|
32
|
+
return _this;
|
33
|
+
}
|
34
|
+
_createClass(TrackerBusSubscriber, [{
|
35
|
+
key: "actionNames",
|
36
|
+
value: function actionNames() {
|
37
|
+
return Object.values(TrackerActionEnum);
|
38
|
+
}
|
39
|
+
}, {
|
40
|
+
key: "reportAnalytics",
|
41
|
+
value: function () {
|
42
|
+
var _reportAnalytics = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(context, message) {
|
43
|
+
var data;
|
44
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
45
|
+
while (1) switch (_context.prev = _context.next) {
|
46
|
+
case 0:
|
47
|
+
console.log('reportAnalytics', message);
|
48
|
+
data = message.getJSONObject();
|
49
|
+
if (this.logger && data !== null && data !== void 0 && data.basic) {
|
50
|
+
if ('error' === (data === null || data === void 0 ? void 0 : data.level)) {
|
51
|
+
this.logger.logError(data === null || data === void 0 ? void 0 : data.basic, data === null || data === void 0 ? void 0 : data.extra);
|
52
|
+
} else {
|
53
|
+
this.logger.logInfo(data === null || data === void 0 ? void 0 : data.basic, data === null || data === void 0 ? void 0 : data.extra);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
case 3:
|
57
|
+
case "end":
|
58
|
+
return _context.stop();
|
59
|
+
}
|
60
|
+
}, _callee, this);
|
61
|
+
}));
|
62
|
+
function reportAnalytics(_x, _x2) {
|
63
|
+
return _reportAnalytics.apply(this, arguments);
|
64
|
+
}
|
65
|
+
return reportAnalytics;
|
66
|
+
}()
|
67
|
+
}, {
|
68
|
+
key: "onMessage",
|
69
|
+
value: function onMessage(context, message) {
|
70
|
+
switch (message.getAction()) {
|
71
|
+
case TrackerActionEnum.reportAnalytics:
|
72
|
+
this.reportAnalytics(context, message);
|
73
|
+
break;
|
74
|
+
default:
|
75
|
+
console.log('Unknown action: ' + message.getAction());
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}]);
|
79
|
+
return TrackerBusSubscriber;
|
80
|
+
}(BusSubscriber);
|
@@ -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 (processResult): bool
|
19
|
+
*/
|
20
|
+
sdk_event_busIsSubscribe = "sdk_event_busIsSubscribe",
|
21
|
+
/**
|
22
|
+
* 订阅协议
|
23
|
+
* actions (actionNames): string[] , 用逗号拼接
|
24
|
+
*/
|
25
|
+
sdk_event_busSubscribe = "sdk_event_busSubscribe",
|
26
|
+
/**
|
27
|
+
* 退订协议
|
28
|
+
* actions (actionNames): 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
|
+
eventSource: '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
|
+
eventSource: '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
|
+
actionName: 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
|
+
actionName: 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
|
+
actionName: 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
|
+
actionName: message.getAction(),
|
243
|
+
instanceId: this.instanceId,
|
244
|
+
errorMessage: 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
|
+
actionName: 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
|
+
actionNames: 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
|
+
actionNames: 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
|
+
actionName: actionName,
|
358
|
+
instanceId: this.instanceId,
|
359
|
+
processResult: 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
|
+
actionName: actionName,
|
381
|
+
instanceId: this.instanceId,
|
382
|
+
processResult: 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
|
+
}
|