@alipay/ams-checkout 0.0.1726734012-dev.1 → 0.0.1726734012-dev.3
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 +133 -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,103 @@
|
|
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 _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; }
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
10
|
+
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); }
|
11
|
+
import { createModal, destroyModal } from "../../../component/popupWindow.style";
|
12
|
+
import { LOADTIME_LIMIT, POPUP_LOADTIME_LOG_LIMIT } from "../../../constant";
|
13
|
+
/**
|
14
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
15
|
+
* @date 2024/9/22
|
16
|
+
*/
|
17
|
+
export var PopupManager = /*#__PURE__*/function () {
|
18
|
+
function PopupManager() {
|
19
|
+
_classCallCheck(this, PopupManager);
|
20
|
+
_defineProperty(this, "popupUrlQuery", void 0);
|
21
|
+
_defineProperty(this, "popupApp", void 0);
|
22
|
+
}
|
23
|
+
_createClass(PopupManager, [{
|
24
|
+
key: "setPopupUrlQuery",
|
25
|
+
value: function setPopupUrlQuery(queryParams) {
|
26
|
+
this.popupUrlQuery = queryParams;
|
27
|
+
}
|
28
|
+
}, {
|
29
|
+
key: "popup",
|
30
|
+
value: function () {
|
31
|
+
var _popup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
|
32
|
+
var error, pageUrl, isLoad, timeout, logTimeout;
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
34
|
+
while (1) switch (_context.prev = _context.next) {
|
35
|
+
case 0:
|
36
|
+
if (data) {
|
37
|
+
_context.next = 5;
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
error = new Error();
|
41
|
+
error.name = 'sdk_error_create_pop_up';
|
42
|
+
error.message = 'Popup failed, input data is undefined';
|
43
|
+
throw error;
|
44
|
+
case 5:
|
45
|
+
pageUrl = data.url;
|
46
|
+
_context.prev = 6;
|
47
|
+
if (this.popupUrlQuery) {
|
48
|
+
pageUrl = data.url.includes('?') ? "".concat(data.url, "&").concat(this.popupUrlQuery) : "".concat(data.url, "?").concat(this.popupUrlQuery);
|
49
|
+
}
|
50
|
+
isLoad = false;
|
51
|
+
_context.next = 11;
|
52
|
+
return createModal({
|
53
|
+
widthPadding: data === null || data === void 0 ? void 0 : data.widthPadding,
|
54
|
+
device: data === null || data === void 0 ? void 0 : data.platform,
|
55
|
+
url: pageUrl,
|
56
|
+
loadingConfig: undefined
|
57
|
+
});
|
58
|
+
case 11:
|
59
|
+
this.popupApp = _context.sent;
|
60
|
+
timeout = setTimeout(function () {
|
61
|
+
if (isLoad) return;
|
62
|
+
throw {
|
63
|
+
title: 'sdk_error_create_pop_up'
|
64
|
+
};
|
65
|
+
}, LOADTIME_LIMIT);
|
66
|
+
logTimeout = setTimeout(function () {
|
67
|
+
if (isLoad) return;
|
68
|
+
throw {
|
69
|
+
title: 'sdk_error_pop_up_time_out'
|
70
|
+
};
|
71
|
+
}, POPUP_LOADTIME_LOG_LIMIT);
|
72
|
+
this.popupApp.onload = function () {
|
73
|
+
isLoad = true;
|
74
|
+
clearTimeout(timeout);
|
75
|
+
clearTimeout(logTimeout);
|
76
|
+
};
|
77
|
+
_context.next = 22;
|
78
|
+
break;
|
79
|
+
case 17:
|
80
|
+
_context.prev = 17;
|
81
|
+
_context.t0 = _context["catch"](6);
|
82
|
+
_context.t0.name = 'sdk_error_create_pop_up';
|
83
|
+
_context.t0.url = pageUrl;
|
84
|
+
throw _context.t0;
|
85
|
+
case 22:
|
86
|
+
case "end":
|
87
|
+
return _context.stop();
|
88
|
+
}
|
89
|
+
}, _callee, this, [[6, 17]]);
|
90
|
+
}));
|
91
|
+
function popup(_x) {
|
92
|
+
return _popup.apply(this, arguments);
|
93
|
+
}
|
94
|
+
return popup;
|
95
|
+
}()
|
96
|
+
}, {
|
97
|
+
key: "pop",
|
98
|
+
value: function pop() {
|
99
|
+
destroyModal();
|
100
|
+
}
|
101
|
+
}]);
|
102
|
+
return PopupManager;
|
103
|
+
}();
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
3
|
+
* @date 2024/9/17
|
4
|
+
*/
|
5
|
+
export declare const createPreloadIframe: (containerId: string) => HTMLIFrameElement;
|
6
|
+
export declare const createIframe: (containerId: string) => HTMLIFrameElement;
|
7
|
+
export declare const startSizeChangeAnim: (target: HTMLDivElement, height: number, animationStyleId: string) => void;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { COMPONENT_CONTAINER_ID } from "../../../constant";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
5
|
+
* @date 2024/9/17
|
6
|
+
*/
|
7
|
+
export var createPreloadIframe = function createPreloadIframe(containerId) {
|
8
|
+
var iframe = document.createElement('iframe');
|
9
|
+
var none = '1px';
|
10
|
+
var width = '1px';
|
11
|
+
iframe.id = containerId;
|
12
|
+
iframe.style.height = none;
|
13
|
+
iframe.style.width = width;
|
14
|
+
iframe.style.border = none;
|
15
|
+
iframe.style.opacity = '0';
|
16
|
+
iframe.style.overflow = 'hidden';
|
17
|
+
return iframe;
|
18
|
+
};
|
19
|
+
export var createIframe = function createIframe(containerId) {
|
20
|
+
var iframe = document.createElement('iframe');
|
21
|
+
var iframeId = containerId;
|
22
|
+
var none = '0';
|
23
|
+
var width = '100%';
|
24
|
+
iframe.id = iframeId;
|
25
|
+
iframe.style.height = none;
|
26
|
+
iframe.style.width = width;
|
27
|
+
iframe.style.border = none;
|
28
|
+
iframe.style.opacity = none;
|
29
|
+
iframe.style.overflow = 'hidden';
|
30
|
+
return iframe;
|
31
|
+
};
|
32
|
+
export var startSizeChangeAnim = function startSizeChangeAnim(target, height, animationStyleId) {
|
33
|
+
// 弹出和弹入动画
|
34
|
+
var runkeyframes = "@keyframes ".concat(COMPONENT_CONTAINER_ID, "-slide-in {\n 0% {\n height: 1px;\n }\n 100% {\n height: ").concat(height, "px;\n }\n }\n @keyframes ").concat(COMPONENT_CONTAINER_ID, "-slide-out {\n 0% {\n height: ").concat(height, "px;\n opacity: 1;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n height: 1px;\n opacity: 0;\n }\n }");
|
35
|
+
// 创建style标签
|
36
|
+
var style = document.createElement('style');
|
37
|
+
style.id = animationStyleId;
|
38
|
+
// 设置style属性
|
39
|
+
style.type = 'text/css';
|
40
|
+
// 将 keyframes样式写入style内
|
41
|
+
style.innerHTML = runkeyframes;
|
42
|
+
// 将style样式存放到head标签
|
43
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
44
|
+
// size变动时动画
|
45
|
+
setTimeout(function () {
|
46
|
+
target.style.transition = 'height 0.28s ease-in-out';
|
47
|
+
}, 500);
|
48
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { EventPayload, EventPayloadContext, IoptionsParams } from '../../types';
|
2
|
+
import { SDKMetaData, 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
|
+
private instanceId;
|
11
|
+
constructor();
|
12
|
+
/**
|
13
|
+
* Initializes the event center
|
14
|
+
*/
|
15
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
16
|
+
/**
|
17
|
+
* Cleans up event listeners when the event center is destroyed.
|
18
|
+
*/
|
19
|
+
destroy(): void;
|
20
|
+
/**
|
21
|
+
* Placeholder for future update logic.
|
22
|
+
*/
|
23
|
+
update(): void;
|
24
|
+
/**
|
25
|
+
* Sets the iframe container and its domain.
|
26
|
+
* @param iframe - The HTMLIFrameElement that serves as the container.
|
27
|
+
* @param domain - The domain of the app.
|
28
|
+
*/
|
29
|
+
addIFrame(iframe: HTMLIFrameElement): void;
|
30
|
+
/**
|
31
|
+
* Cleans iframes when web app close
|
32
|
+
*/
|
33
|
+
cleanIFrames(): void;
|
34
|
+
removeIFrame(iframe: HTMLIFrameElement): void;
|
35
|
+
/**
|
36
|
+
* Handles messages received from the app.
|
37
|
+
* @param e - The message event.
|
38
|
+
*/
|
39
|
+
private handleAppMessage;
|
40
|
+
private checkEventCompliant;
|
41
|
+
/**
|
42
|
+
* Processes the application message and emits the associated event.
|
43
|
+
* @param data - Parsed EventPayload from the app.
|
44
|
+
*/
|
45
|
+
private _handleAppMessage;
|
46
|
+
/**
|
47
|
+
* Listens to an event by adding a callback function.
|
48
|
+
* @param name - The name of the event to listen for.
|
49
|
+
* @param func - The callback function to execute when the event is emitted.
|
50
|
+
* @param isAppend - Append to event handlers as chain, default value is false
|
51
|
+
*/
|
52
|
+
listen(name: string, func: IListener, isAppend?: boolean): void;
|
53
|
+
/**
|
54
|
+
* Unsubscribes from an event. If a function is provided, only that function is removed.
|
55
|
+
* @param name - The name of the event to unlisten to.
|
56
|
+
* @param func - The optional callback function to remove.
|
57
|
+
*/
|
58
|
+
unlisten(name: string, func?: IListener): void;
|
59
|
+
/**
|
60
|
+
* Emits an event, executing all associated callback functions.
|
61
|
+
* @param name - The name of the event to emit.
|
62
|
+
* @param data - The event data to pass to the event listeners.
|
63
|
+
*/
|
64
|
+
emit(name: string, data: any, eventPayload?: EventPayload): void;
|
65
|
+
/**
|
66
|
+
* Registers a callback for an event and immediately dispatches the event to the app.
|
67
|
+
* @param payloadContext - The context containing event information and callback ID.
|
68
|
+
* @param func - The callback function to execute when the event is emitted.
|
69
|
+
*/
|
70
|
+
emitAndListen(payloadContext: EventPayloadContext, func: IListener): void;
|
71
|
+
queryParse(url?: string): Record<string, any>;
|
72
|
+
/**
|
73
|
+
* Dispatches the event payload to the app via postMessage.
|
74
|
+
* @param payloadContext - The context containing event to be dispatched.
|
75
|
+
*/
|
76
|
+
dispatchToApp(payloadContext: EventPayloadContext): void;
|
77
|
+
isExist(name: string): boolean;
|
78
|
+
}
|
79
|
+
interface IListener {
|
80
|
+
(data: any, eventPayload?: EventPayload): void;
|
81
|
+
}
|
82
|
+
export {};
|
@@ -0,0 +1,274 @@
|
|
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 { v4 as uuid } from 'uuid';
|
11
|
+
import { ERRORMESSAGE } from "../../constant";
|
12
|
+
import { MessageName } from "../../types";
|
13
|
+
import { isJsonString } from "../../util";
|
14
|
+
import { getIframeOrigin, registerSystemEvents, unRegisterSystemEvents } from "../utils/system_events";
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @author 江跃 <jiangbin.gjb@antgroup.com>
|
18
|
+
* @date 2024/9/17
|
19
|
+
*/
|
20
|
+
export var EventCenter = /*#__PURE__*/function () {
|
21
|
+
function EventCenter() {
|
22
|
+
_classCallCheck(this, EventCenter);
|
23
|
+
_defineProperty(this, "events", void 0);
|
24
|
+
_defineProperty(this, "iframes", void 0);
|
25
|
+
_defineProperty(this, "instanceId", void 0);
|
26
|
+
this.events = new Map();
|
27
|
+
this.iframes = [];
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Initializes the event center
|
32
|
+
*/
|
33
|
+
_createClass(EventCenter, [{
|
34
|
+
key: "init",
|
35
|
+
value: function init(initOptions, instanceId, sdkMetaData) {
|
36
|
+
this.instanceId = instanceId;
|
37
|
+
this.handleAppMessage = this.handleAppMessage.bind(this);
|
38
|
+
window.addEventListener('message', this.handleAppMessage);
|
39
|
+
registerSystemEvents(this);
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Cleans up event listeners when the event center is destroyed.
|
44
|
+
*/
|
45
|
+
}, {
|
46
|
+
key: "destroy",
|
47
|
+
value: function destroy() {
|
48
|
+
window.removeEventListener('message', this.handleAppMessage);
|
49
|
+
this.iframes = [];
|
50
|
+
unRegisterSystemEvents(this);
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Placeholder for future update logic.
|
55
|
+
*/
|
56
|
+
}, {
|
57
|
+
key: "update",
|
58
|
+
value: function update() {
|
59
|
+
// TODO:
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Sets the iframe container and its domain.
|
64
|
+
* @param iframe - The HTMLIFrameElement that serves as the container.
|
65
|
+
* @param domain - The domain of the app.
|
66
|
+
*/
|
67
|
+
}, {
|
68
|
+
key: "addIFrame",
|
69
|
+
value: function addIFrame(iframe) {
|
70
|
+
this.iframes.push({
|
71
|
+
ref: iframe,
|
72
|
+
origin: getIframeOrigin(iframe)
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Cleans iframes when web app close
|
78
|
+
*/
|
79
|
+
}, {
|
80
|
+
key: "cleanIFrames",
|
81
|
+
value: function cleanIFrames() {
|
82
|
+
this.iframes = [];
|
83
|
+
}
|
84
|
+
}, {
|
85
|
+
key: "removeIFrame",
|
86
|
+
value: function removeIFrame(iframe) {
|
87
|
+
var index = this.iframes.findIndex(function (item) {
|
88
|
+
return item.origin === getIframeOrigin(iframe);
|
89
|
+
});
|
90
|
+
if (index !== -1) {
|
91
|
+
this.iframes.splice(index, 1);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Handles messages received from the app.
|
97
|
+
* @param e - The message event.
|
98
|
+
*/
|
99
|
+
}, {
|
100
|
+
key: "handleAppMessage",
|
101
|
+
value: function handleAppMessage(e) {
|
102
|
+
var _e$data;
|
103
|
+
if (!this.iframes.some(function (iframe) {
|
104
|
+
return iframe.origin === e.origin;
|
105
|
+
})) return;
|
106
|
+
if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
|
107
|
+
return; // Ignore messages from React DevTools
|
108
|
+
}
|
109
|
+
var isJson = isJsonString(e.data);
|
110
|
+
if (isJson) {
|
111
|
+
var _eventPayload = JSON.parse(e.data);
|
112
|
+
if (!this.checkEventCompliant(_eventPayload)) {
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
this._handleAppMessage(_eventPayload);
|
116
|
+
} else {
|
117
|
+
console.error(ERRORMESSAGE.NOT_JSON_FORMAT);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}, {
|
121
|
+
key: "checkEventCompliant",
|
122
|
+
value: function checkEventCompliant(eventPayload) {
|
123
|
+
// connect element场景下,多子iframes共用AntomCore中生成的instanceId,此时将发送事件方instanceId与iframes中instanceId做比较看是否在其中
|
124
|
+
// 非connect场景下,直接将发送事件方instanceId与AntomCore的instanceId做比较
|
125
|
+
if (eventPayload.name !== MessageName.APP_TO_SDK) {
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
var iframesInstanceIds = this.iframes.map(function (iframe) {
|
129
|
+
var _iframe$ref;
|
130
|
+
if (!new URL((_iframe$ref = iframe.ref) === null || _iframe$ref === void 0 ? void 0 : _iframe$ref.src)) {
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
return new URL(iframe.ref.src).searchParams.get('instanceId');
|
134
|
+
}).filter(Boolean);
|
135
|
+
if (eventPayload.instanceId !== this.instanceId && !iframesInstanceIds.includes(eventPayload.instanceId)) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
return true;
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Processes the application message and emits the associated event.
|
143
|
+
* @param data - Parsed EventPayload from the app.
|
144
|
+
*/
|
145
|
+
}, {
|
146
|
+
key: "_handleAppMessage",
|
147
|
+
value: function _handleAppMessage(eventPayload) {
|
148
|
+
var context = eventPayload.context;
|
149
|
+
var event = context.event,
|
150
|
+
data = context.data;
|
151
|
+
this.emit(event, data, eventPayload);
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Listens to an event by adding a callback function.
|
156
|
+
* @param name - The name of the event to listen for.
|
157
|
+
* @param func - The callback function to execute when the event is emitted.
|
158
|
+
* @param isAppend - Append to event handlers as chain, default value is false
|
159
|
+
*/
|
160
|
+
}, {
|
161
|
+
key: "listen",
|
162
|
+
value: function listen(name, func) {
|
163
|
+
var isAppend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
164
|
+
var eventList = isAppend ? this.events.get(name) || [] : [];
|
165
|
+
eventList.push({
|
166
|
+
func: func
|
167
|
+
});
|
168
|
+
this.events.set(name, eventList);
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Unsubscribes from an event. If a function is provided, only that function is removed.
|
173
|
+
* @param name - The name of the event to unlisten to.
|
174
|
+
* @param func - The optional callback function to remove.
|
175
|
+
*/
|
176
|
+
}, {
|
177
|
+
key: "unlisten",
|
178
|
+
value: function unlisten(name, func) {
|
179
|
+
if (func) {
|
180
|
+
if (this.events.has(name)) {
|
181
|
+
var eventList = this.events.get(name);
|
182
|
+
eventList = eventList.filter(function (item) {
|
183
|
+
return item.func !== func;
|
184
|
+
});
|
185
|
+
this.events.set(name, eventList);
|
186
|
+
}
|
187
|
+
} else {
|
188
|
+
this.events.delete(name);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Emits an event, executing all associated callback functions.
|
194
|
+
* @param name - The name of the event to emit.
|
195
|
+
* @param data - The event data to pass to the event listeners.
|
196
|
+
*/
|
197
|
+
}, {
|
198
|
+
key: "emit",
|
199
|
+
value: function emit(name, data, eventPayload) {
|
200
|
+
if (this.events.has(name)) {
|
201
|
+
var eventList = this.events.get(name);
|
202
|
+
eventList.forEach(function (item) {
|
203
|
+
item.func(data, eventPayload);
|
204
|
+
});
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Registers a callback for an event and immediately dispatches the event to the app.
|
210
|
+
* @param payloadContext - The context containing event information and callback ID.
|
211
|
+
* @param func - The callback function to execute when the event is emitted.
|
212
|
+
*/
|
213
|
+
}, {
|
214
|
+
key: "emitAndListen",
|
215
|
+
value: function emitAndListen(payloadContext, func) {
|
216
|
+
if (!payloadContext.eventCallbackId) {
|
217
|
+
payloadContext.eventCallbackId = uuid();
|
218
|
+
}
|
219
|
+
this.listen(payloadContext.eventCallbackId, func);
|
220
|
+
this.dispatchToApp(payloadContext);
|
221
|
+
}
|
222
|
+
}, {
|
223
|
+
key: "queryParse",
|
224
|
+
value: function queryParse(url) {
|
225
|
+
var qs = {};
|
226
|
+
var urlString = url;
|
227
|
+
if (!urlString) {
|
228
|
+
urlString = window.location.href;
|
229
|
+
}
|
230
|
+
urlString.replace(/([^?=&#]+)(=([^&#]*))?/g, function (_$0, $1, _$2, $3) {
|
231
|
+
if ($3 === undefined) {
|
232
|
+
return '';
|
233
|
+
}
|
234
|
+
qs[$1] = decodeURIComponent($3);
|
235
|
+
return qs[$1];
|
236
|
+
});
|
237
|
+
return qs;
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Dispatches the event payload to the app via postMessage.
|
242
|
+
* @param payloadContext - The context containing event to be dispatched.
|
243
|
+
*/
|
244
|
+
}, {
|
245
|
+
key: "dispatchToApp",
|
246
|
+
value: function dispatchToApp(payloadContext) {
|
247
|
+
var _this$iframes,
|
248
|
+
_this = this;
|
249
|
+
var data = {
|
250
|
+
name: MessageName.SDK_TO_APP,
|
251
|
+
context: payloadContext,
|
252
|
+
instanceId: this.instanceId
|
253
|
+
};
|
254
|
+
(_this$iframes = this.iframes) === null || _this$iframes === void 0 || _this$iframes.forEach(function (iframe) {
|
255
|
+
var _iframe$origin;
|
256
|
+
if (!iframe.ref.contentWindow) {
|
257
|
+
console.error('get app contentWindow error', iframe);
|
258
|
+
return;
|
259
|
+
}
|
260
|
+
var _ref = _this.queryParse(iframe.ref.src) || {},
|
261
|
+
instanceId = _ref.instanceId;
|
262
|
+
iframe.ref.contentWindow.postMessage(JSON.stringify(_objectSpread(_objectSpread({}, data), {}, {
|
263
|
+
instanceId: instanceId
|
264
|
+
})), (_iframe$origin = iframe.origin) !== null && _iframe$origin !== void 0 ? _iframe$origin : '*');
|
265
|
+
});
|
266
|
+
}
|
267
|
+
}, {
|
268
|
+
key: "isExist",
|
269
|
+
value: function isExist(name) {
|
270
|
+
return this.events.has(name);
|
271
|
+
}
|
272
|
+
}]);
|
273
|
+
return EventCenter;
|
274
|
+
}();
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { IoptionsParams } from "../../../types";
|
2
|
+
import { Service } from "../../index";
|
3
|
+
export declare class GlobalDataService implements Service {
|
4
|
+
private globalData;
|
5
|
+
init(initOptions: IoptionsParams, instanceId: string): void;
|
6
|
+
destroy(): void;
|
7
|
+
update(): void;
|
8
|
+
getGlobalData(dataKey: string): any;
|
9
|
+
setGlobalData(dataKey: string, data: any): void;
|
10
|
+
clearGlobalData(): void;
|
11
|
+
}
|
@@ -0,0 +1,68 @@
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
3
|
+
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); } }
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
5
|
+
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; }
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
7
|
+
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); }
|
8
|
+
import { ServiceProvider } from "../index";
|
9
|
+
import { EVENT } from "../../../constant";
|
10
|
+
export var GlobalDataService = /*#__PURE__*/function () {
|
11
|
+
function GlobalDataService() {
|
12
|
+
_classCallCheck(this, GlobalDataService);
|
13
|
+
_defineProperty(this, "globalData", new Map());
|
14
|
+
}
|
15
|
+
_createClass(GlobalDataService, [{
|
16
|
+
key: "init",
|
17
|
+
value: function init(initOptions, instanceId) {
|
18
|
+
var _this = this;
|
19
|
+
// add capability to EventCenter
|
20
|
+
var eventCenter = ServiceProvider.getInstance(instanceId).getService('EventCenter');
|
21
|
+
eventCenter.listen(EVENT.getGlobalData.name, function (data, payload) {
|
22
|
+
var _payload$context, _payload$context2, _payload$context3, _payload$context4;
|
23
|
+
if (!((_payload$context = payload.context) !== null && _payload$context !== void 0 && _payload$context.eventCallbackId) || !((_payload$context2 = payload.context) !== null && _payload$context2 !== void 0 && (_payload$context2 = _payload$context2.data) !== null && _payload$context2 !== void 0 && _payload$context2.dataKey)) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
var targetData = _this.globalData.get((_payload$context3 = payload.context) === null || _payload$context3 === void 0 || (_payload$context3 = _payload$context3.data) === null || _payload$context3 === void 0 ? void 0 : _payload$context3.dataKey);
|
27
|
+
eventCenter.dispatchToApp({
|
28
|
+
event: 'appEventCallback',
|
29
|
+
eventCallbackId: (_payload$context4 = payload.context) === null || _payload$context4 === void 0 ? void 0 : _payload$context4.eventCallbackId,
|
30
|
+
data: targetData
|
31
|
+
});
|
32
|
+
});
|
33
|
+
eventCenter.listen(EVENT.setGlobalData.name, function (data) {
|
34
|
+
if (!(data !== null && data !== void 0 && data.dataKey) || !(data !== null && data !== void 0 && data.data)) {
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
_this.globalData.set(data.dataKey, data.data);
|
38
|
+
});
|
39
|
+
|
40
|
+
// register
|
41
|
+
}
|
42
|
+
}, {
|
43
|
+
key: "destroy",
|
44
|
+
value: function destroy() {
|
45
|
+
this.globalData.clear();
|
46
|
+
}
|
47
|
+
}, {
|
48
|
+
key: "update",
|
49
|
+
value: function update() {}
|
50
|
+
}, {
|
51
|
+
key: "getGlobalData",
|
52
|
+
value: function getGlobalData(dataKey) {
|
53
|
+
var targetData = this.globalData.get(dataKey);
|
54
|
+
return targetData;
|
55
|
+
}
|
56
|
+
}, {
|
57
|
+
key: "setGlobalData",
|
58
|
+
value: function setGlobalData(dataKey, data) {
|
59
|
+
this.globalData.set(dataKey, data);
|
60
|
+
}
|
61
|
+
}, {
|
62
|
+
key: "clearGlobalData",
|
63
|
+
value: function clearGlobalData() {
|
64
|
+
this.globalData = new Map();
|
65
|
+
}
|
66
|
+
}]);
|
67
|
+
return GlobalDataService;
|
68
|
+
}();
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { IoptionsParams } from '../../types';
|
2
|
+
import { PaymentContext, SDKMetaData, Service } from '../index';
|
3
|
+
/**
|
4
|
+
* @author 谦彧 <zhangmian.zm@alipay.com>
|
5
|
+
* @date 2024/9/17
|
6
|
+
*/
|
7
|
+
export type ServiceName = 'Container' | 'EventCenter' | 'Log' | 'ApiBusManager' | 'Requester' | 'Security' | 'GlobalData';
|
8
|
+
export declare class ServiceProvider {
|
9
|
+
private static ProvidersMapping;
|
10
|
+
static getInstance(instanceId: string): ServiceProvider;
|
11
|
+
private readonly instanceId;
|
12
|
+
private services;
|
13
|
+
private extendServices;
|
14
|
+
private constructor();
|
15
|
+
init(initOptions: IoptionsParams, sdkMetaData: SDKMetaData): void;
|
16
|
+
update(paymentContext: PaymentContext): void;
|
17
|
+
getService<T>(serviceName: ServiceName): T;
|
18
|
+
registerService(serviceName: string, service: Service): void;
|
19
|
+
}
|