@alipay/ams-checkout 0.0.1761013649-dev.1 → 0.0.1761220900-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/constant/auto-debit.d.ts +12 -0
- package/esm/constant/auto-debit.js +15 -0
- package/esm/constant/element.d.ts +26 -0
- package/esm/constant/element.js +30 -0
- package/esm/constant/index.d.ts +1 -1
- package/esm/constant/index.js +4 -4
- package/esm/core/component/element/elementController/index.js +2 -2
- package/esm/core/component/element/elementProcessor/addressProcessor.js +2 -3
- package/esm/core/component/element/elementProcessor/authProcessor.js +2 -3
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +1 -1
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +30 -28
- package/esm/foundation/utils/web_app_url_utils.d.ts +0 -2
- package/esm/foundation/utils/web_app_url_utils.js +10 -15
- package/esm/index.d.ts +13 -52
- package/esm/index.js +19 -339
- package/esm/loader/Proxy.d.ts +5 -0
- package/esm/loader/Proxy.js +244 -0
- package/esm/loader/constant.d.ts +33 -0
- package/esm/loader/constant.js +35 -0
- package/esm/loader/index.d.ts +18 -0
- package/esm/loader/index.js +23 -0
- package/esm/loader/utils/common.d.ts +9 -0
- package/esm/loader/utils/common.js +53 -0
- package/esm/loader/utils/debugger.d.ts +7 -0
- package/esm/loader/utils/debugger.js +15 -0
- package/esm/loader/utils/loadSDK.d.ts +3 -0
- package/esm/loader/utils/loadSDK.js +75 -0
- package/esm/loader/utils/logger.d.ts +10 -0
- package/esm/loader/utils/logger.js +59 -0
- package/esm/main.d.ts +45 -0
- package/esm/main.js +329 -0
- package/esm/plugin/component/cashierApp.js +5 -4
- package/esm/util/integrationType.d.ts +21 -0
- package/esm/util/integrationType.js +51 -0
- package/esm/util/logger.d.ts +2 -0
- package/esm/util/logger.js +1 -1
- package/package.json +6 -1
package/esm/index.js
CHANGED
|
@@ -1,343 +1,23 @@
|
|
|
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 _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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
-
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); }
|
|
7
|
-
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; }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
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 _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); } }
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
-
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); }
|
|
15
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
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); }
|
|
17
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
|
-
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); }; }
|
|
19
|
-
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); }
|
|
20
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
-
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; } }
|
|
22
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
1
|
/**
|
|
24
|
-
*
|
|
2
|
+
* NPM包入口 产品持续接入热更新中
|
|
25
3
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export {
|
|
4
|
+
* 背景:
|
|
5
|
+
* 通过NPM方式集成SDK,各产品需要持续接入热更新, 接入热更新的产品基类仅导出热更新壳
|
|
6
|
+
* 通过UMD方式集成SDK, 各产品基类直接导出
|
|
7
|
+
*
|
|
8
|
+
* 详见: https://yuque.antfin.com/antom-sdk/dg6hge/lbun86wg2h3f7es7
|
|
9
|
+
*
|
|
10
|
+
* **/
|
|
11
|
+
import { AMSCheckout } from "./main";
|
|
12
|
+
import { injectAntomSDKIntegrationType } from "./util/integrationType";
|
|
13
|
+
|
|
14
|
+
// 注入集成类型标记
|
|
15
|
+
injectAntomSDKIntegrationType('NPM');
|
|
16
|
+
|
|
17
|
+
// 已接入热更新的产品
|
|
18
|
+
export { AMSEasyPayWrapper as AMSEasyPay, AMSElementWrapper as AMSElement } from "./loader/index";
|
|
19
|
+
// 未接入热更新的产品
|
|
20
|
+
export { AddressElement, AMSAutoDebit, AMSAutoDebitPay, AMSCashierPayment, AMSCheckout, AMSCheckoutPage, AMSVaulting, AntomElement } from "./main";
|
|
21
|
+
// 全量类型&常量导出
|
|
41
22
|
export * from "./types";
|
|
42
|
-
import { EVENT } from "./constant";
|
|
43
|
-
import { AntomSDKCore } from "./foundation/core";
|
|
44
|
-
import { AutoDebitProcessor } from "./foundation/product-processor/autoDebit";
|
|
45
|
-
import { EasySafePayProcessor } from "./foundation/product-processor/easysafepay";
|
|
46
|
-
export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
|
|
47
|
-
_inherits(AMSCheckout, _AMSComponent);
|
|
48
|
-
var _super = _createSuper(AMSCheckout);
|
|
49
|
-
function AMSCheckout(_options, channelType) {
|
|
50
|
-
var _this;
|
|
51
|
-
var productSceneVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '1.0';
|
|
52
|
-
_classCallCheck(this, AMSCheckout);
|
|
53
|
-
_this = _super.call(this, _objectSpread({
|
|
54
|
-
appVersion: AMSCheckoutAppVersion
|
|
55
|
-
}, _options));
|
|
56
|
-
_this.preloadComponent(channelType, productSceneVersion);
|
|
57
|
-
return _this;
|
|
58
|
-
}
|
|
59
|
-
return _createClass(AMSCheckout);
|
|
60
|
-
}(AMSComponent);
|
|
61
|
-
export var AMSAutoDebitPay = /*#__PURE__*/function (_AMSCheckout) {
|
|
62
|
-
_inherits(AMSAutoDebitPay, _AMSCheckout);
|
|
63
|
-
var _super2 = _createSuper(AMSAutoDebitPay);
|
|
64
|
-
function AMSAutoDebitPay(options) {
|
|
65
|
-
_classCallCheck(this, AMSAutoDebitPay);
|
|
66
|
-
var _options = Object.assign({}, options, {
|
|
67
|
-
product: ProductSceneEnum.AUTO_DEBIT_PAY
|
|
68
|
-
});
|
|
69
|
-
return _super2.call(this, _options, [ComponentSignEnum.AUTO_DEBIT_PAY_WALLET]);
|
|
70
|
-
}
|
|
71
|
-
_createClass(AMSAutoDebitPay, null, [{
|
|
72
|
-
key: "preload",
|
|
73
|
-
value: function preload() {
|
|
74
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
75
|
-
securityRegion: 'SG',
|
|
76
|
-
environment: 'prod'
|
|
77
|
-
};
|
|
78
|
-
PreloadHelper.preloadWebApp(ProductSceneEnum.AUTO_DEBIT_PAY, PaymentMethodCategoryTypeEnum.WALLET, options.environment);
|
|
79
|
-
PreloadHelper.preloadSecuritySDK(ProductSceneEnum.AUTO_DEBIT_PAY, options.securityRegion);
|
|
80
|
-
}
|
|
81
|
-
}]);
|
|
82
|
-
return AMSAutoDebitPay;
|
|
83
|
-
}(AMSCheckout);
|
|
84
|
-
export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout2) {
|
|
85
|
-
_inherits(AMSCashierPayment, _AMSCheckout2);
|
|
86
|
-
var _super3 = _createSuper(AMSCashierPayment);
|
|
87
|
-
function AMSCashierPayment(options) {
|
|
88
|
-
_classCallCheck(this, AMSCashierPayment);
|
|
89
|
-
var _options = Object.assign({}, options, {
|
|
90
|
-
product: ProductSceneEnum.CASHIER_PAYMENT,
|
|
91
|
-
appVersion: AMSCashierPaymentAppVersion
|
|
92
|
-
});
|
|
93
|
-
var currentChannelType;
|
|
94
|
-
try {
|
|
95
|
-
var previousChannelStr = localStorage.getItem('antom_checkout_previousChannel');
|
|
96
|
-
var previousChannel = JSON.parse(previousChannelStr) || {};
|
|
97
|
-
var _ref = previousChannel || {},
|
|
98
|
-
_ref$channelType = _ref.channelType,
|
|
99
|
-
channelType = _ref$channelType === void 0 ? '' : _ref$channelType;
|
|
100
|
-
if ([ComponentSignEnum.CASHIER_PAYMENT_CARD, ComponentSignEnum.CASHIER_PAYMENT_APM, ComponentSignEnum.CASHIER_PAYMENT_BANK].includes(channelType)) {
|
|
101
|
-
currentChannelType = [channelType];
|
|
102
|
-
} else {
|
|
103
|
-
currentChannelType = [ComponentSignEnum.CASHIER_PAYMENT_CARD, ComponentSignEnum.CASHIER_PAYMENT_APM];
|
|
104
|
-
}
|
|
105
|
-
} catch (error) {
|
|
106
|
-
logger.logError({
|
|
107
|
-
title: 'performance_optimization_get_previousChannel_error'
|
|
108
|
-
}, {
|
|
109
|
-
errorMessage: error
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return _super3.call(this, _options, currentChannelType);
|
|
113
|
-
}
|
|
114
|
-
_createClass(AMSCashierPayment, [{
|
|
115
|
-
key: "validateFields",
|
|
116
|
-
value:
|
|
117
|
-
/**
|
|
118
|
-
* Form validation function
|
|
119
|
-
* If the form is currently displayed:
|
|
120
|
-
* - Successful validation: isValid is true
|
|
121
|
-
* - Failed validation: isValid is false, and error messages are displayed on the form page
|
|
122
|
-
* If not on the form display page, isValid returns false
|
|
123
|
-
* @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
|
|
124
|
-
*/
|
|
125
|
-
function validateFields() {
|
|
126
|
-
return this._validateFields();
|
|
127
|
-
}
|
|
128
|
-
}], [{
|
|
129
|
-
key: "preload",
|
|
130
|
-
value: function preload() {
|
|
131
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
132
|
-
securityRegion: 'SG',
|
|
133
|
-
environment: 'prod'
|
|
134
|
-
};
|
|
135
|
-
try {
|
|
136
|
-
var channelTypes;
|
|
137
|
-
var previousChannelStr = localStorage.getItem('antom_checkout_previousChannel');
|
|
138
|
-
var previousChannel = JSON.parse(previousChannelStr) || {};
|
|
139
|
-
var _ref2 = previousChannel || {},
|
|
140
|
-
_ref2$channelType = _ref2.channelType,
|
|
141
|
-
channelType = _ref2$channelType === void 0 ? '' : _ref2$channelType;
|
|
142
|
-
if (ComponentSignEnum.CASHIER_PAYMENT_CARD === channelType) {
|
|
143
|
-
channelTypes = [PaymentMethodCategoryTypeEnum.CARD];
|
|
144
|
-
} else if (ComponentSignEnum.CASHIER_PAYMENT_APM === channelType) {
|
|
145
|
-
channelTypes = [PaymentMethodCategoryTypeEnum.APM];
|
|
146
|
-
} else if (ComponentSignEnum.CASHIER_PAYMENT_BANK === channelType) {
|
|
147
|
-
channelTypes = [PaymentMethodCategoryTypeEnum.BANK];
|
|
148
|
-
} else {
|
|
149
|
-
channelTypes = [PaymentMethodCategoryTypeEnum.CARD, PaymentMethodCategoryTypeEnum.APM];
|
|
150
|
-
}
|
|
151
|
-
var _iterator = _createForOfIteratorHelper(channelTypes),
|
|
152
|
-
_step;
|
|
153
|
-
try {
|
|
154
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
155
|
-
var _channelType = _step.value;
|
|
156
|
-
PreloadHelper.preloadWebApp(ProductSceneEnum.CASHIER_PAYMENT, _channelType, options.environment);
|
|
157
|
-
}
|
|
158
|
-
} catch (err) {
|
|
159
|
-
_iterator.e(err);
|
|
160
|
-
} finally {
|
|
161
|
-
_iterator.f();
|
|
162
|
-
}
|
|
163
|
-
} catch (error) {
|
|
164
|
-
console.error('[web-sdk] preload web app error', error);
|
|
165
|
-
}
|
|
166
|
-
PreloadHelper.preloadSecuritySDK(ProductSceneEnum.CASHIER_PAYMENT, options.securityRegion);
|
|
167
|
-
}
|
|
168
|
-
}]);
|
|
169
|
-
return AMSCashierPayment;
|
|
170
|
-
}(AMSCheckout);
|
|
171
|
-
export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout3) {
|
|
172
|
-
_inherits(AMSVaulting, _AMSCheckout3);
|
|
173
|
-
var _super4 = _createSuper(AMSVaulting);
|
|
174
|
-
function AMSVaulting(options) {
|
|
175
|
-
_classCallCheck(this, AMSVaulting);
|
|
176
|
-
var _options = Object.assign({}, options, {
|
|
177
|
-
product: ProductSceneEnum.VAULTING,
|
|
178
|
-
appVersion: AMSVaultingAppVersion
|
|
179
|
-
});
|
|
180
|
-
return _super4.call(this, _options, [ComponentSignEnum.CASHIER_PAYMENT_CARD]);
|
|
181
|
-
}
|
|
182
|
-
_createClass(AMSVaulting, null, [{
|
|
183
|
-
key: "preload",
|
|
184
|
-
value: function preload() {
|
|
185
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
186
|
-
securityRegion: 'SG',
|
|
187
|
-
environment: 'prod'
|
|
188
|
-
};
|
|
189
|
-
PreloadHelper.preloadWebApp(ProductSceneEnum.CASHIER_PAYMENT, PaymentMethodCategoryTypeEnum.CARD, options.environment);
|
|
190
|
-
PreloadHelper.preloadSecuritySDK(ProductSceneEnum.VAULTING, options.securityRegion);
|
|
191
|
-
}
|
|
192
|
-
}]);
|
|
193
|
-
return AMSVaulting;
|
|
194
|
-
}(AMSCheckout);
|
|
195
|
-
export var AntomElement = /*#__PURE__*/function (_AMSCheckout4) {
|
|
196
|
-
_inherits(AntomElement, _AMSCheckout4);
|
|
197
|
-
var _super5 = _createSuper(AntomElement);
|
|
198
|
-
function AntomElement(options) {
|
|
199
|
-
_classCallCheck(this, AntomElement);
|
|
200
|
-
var _options = Object.assign({}, options, {
|
|
201
|
-
product: ProductSceneEnum.ELEMENT_PAYMENT,
|
|
202
|
-
appVersion: AMSPaymentElementAppVersion
|
|
203
|
-
});
|
|
204
|
-
return _super5.call(this, _options, [ComponentSignEnum.ELEMENT_PAYMENT]);
|
|
205
|
-
}
|
|
206
|
-
return _createClass(AntomElement);
|
|
207
|
-
}(AMSCheckout);
|
|
208
|
-
export var AddressElement = /*#__PURE__*/function (_AddressComponent) {
|
|
209
|
-
_inherits(AddressElement, _AddressComponent);
|
|
210
|
-
var _super6 = _createSuper(AddressElement);
|
|
211
|
-
function AddressElement(options) {
|
|
212
|
-
_classCallCheck(this, AddressElement);
|
|
213
|
-
var _options = Object.assign({}, options, {
|
|
214
|
-
product: ProductSceneEnum.ELEMENT_ADDRESS,
|
|
215
|
-
appVersion: ADDRESSElementAppVersion
|
|
216
|
-
});
|
|
217
|
-
return _super6.call(this, _options);
|
|
218
|
-
}
|
|
219
|
-
return _createClass(AddressElement);
|
|
220
|
-
}(AddressComponent);
|
|
221
|
-
export var AMSElement = /*#__PURE__*/function (_ElementComponent) {
|
|
222
|
-
_inherits(AMSElement, _ElementComponent);
|
|
223
|
-
var _super7 = _createSuper(AMSElement);
|
|
224
|
-
function AMSElement(options) {
|
|
225
|
-
_classCallCheck(this, AMSElement);
|
|
226
|
-
var _options = Object.assign({}, options, {
|
|
227
|
-
product: ProductSceneEnum.ELEMENT_PAYMENT,
|
|
228
|
-
environment: options.environment
|
|
229
|
-
});
|
|
230
|
-
return _super7.call(this, _options);
|
|
231
|
-
}
|
|
232
|
-
return _createClass(AMSElement);
|
|
233
|
-
}(ElementComponent);
|
|
234
|
-
export var AMSEasyPay = /*#__PURE__*/function () {
|
|
235
|
-
function AMSEasyPay(options) {
|
|
236
|
-
_classCallCheck(this, AMSEasyPay);
|
|
237
|
-
_defineProperty(this, "core", void 0);
|
|
238
|
-
this.core = new AntomSDKCore();
|
|
239
|
-
this.core.registerProcessor(ProductSceneEnum.EASY_PAY, '', new EasySafePayProcessor());
|
|
240
|
-
this.core.init(options, ProductSceneEnum.EASY_PAY);
|
|
241
|
-
}
|
|
242
|
-
_createClass(AMSEasyPay, [{
|
|
243
|
-
key: "createComponent",
|
|
244
|
-
value: function createComponent(params) {
|
|
245
|
-
this.core.startBizFlow({
|
|
246
|
-
submitPayRequestExtra: {
|
|
247
|
-
notRedirectAfterComplete: params.notRedirectAfterComplete,
|
|
248
|
-
merchantAppointParam: params.merchantAppointParam
|
|
249
|
-
},
|
|
250
|
-
paymentSession: params.sessionData || params.paymentSessionData,
|
|
251
|
-
displayInfo: {
|
|
252
|
-
type: DisplayTypeEnum.popup
|
|
253
|
-
},
|
|
254
|
-
isAppWebview: params.isAppWebview,
|
|
255
|
-
isNativeAppWebview: params.isNativeAppWebview
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
key: "unmount",
|
|
260
|
-
value: function unmount() {
|
|
261
|
-
this.core.destroy();
|
|
262
|
-
}
|
|
263
|
-
}], [{
|
|
264
|
-
key: "preload",
|
|
265
|
-
value: function preload() {
|
|
266
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
267
|
-
securityRegion: 'SG',
|
|
268
|
-
environment: 'prod'
|
|
269
|
-
};
|
|
270
|
-
PreloadHelper.preloadWebApp(ProductSceneEnum.EASY_PAY, PaymentMethodCategoryTypeEnum.WALLET, options.environment, true);
|
|
271
|
-
}
|
|
272
|
-
}]);
|
|
273
|
-
return AMSEasyPay;
|
|
274
|
-
}();
|
|
275
|
-
export var AMSAutoDebit = /*#__PURE__*/function () {
|
|
276
|
-
function AMSAutoDebit(options) {
|
|
277
|
-
_classCallCheck(this, AMSAutoDebit);
|
|
278
|
-
_defineProperty(this, "core", void 0);
|
|
279
|
-
this.core = new AntomSDKCore();
|
|
280
|
-
this.core.registerProcessor(ProductSceneEnum.AUTO_DEBIT, '', new AutoDebitProcessor());
|
|
281
|
-
this.core.init(options, ProductSceneEnum.AUTO_DEBIT);
|
|
282
|
-
}
|
|
283
|
-
_createClass(AMSAutoDebit, [{
|
|
284
|
-
key: "createComponent",
|
|
285
|
-
value: function () {
|
|
286
|
-
var _createComponent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
287
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
288
|
-
while (1) switch (_context.prev = _context.next) {
|
|
289
|
-
case 0:
|
|
290
|
-
_context.prev = 0;
|
|
291
|
-
_context.next = 3;
|
|
292
|
-
return this.core.startBizFlow({
|
|
293
|
-
submitPayRequestExtra: {
|
|
294
|
-
notRedirectAfterComplete: params.notRedirectAfterComplete,
|
|
295
|
-
merchantAppointParam: params.merchantAppointParam
|
|
296
|
-
},
|
|
297
|
-
paymentSession: params.sessionData || params.paymentSessionData,
|
|
298
|
-
displayInfo: {
|
|
299
|
-
type: DisplayTypeEnum.popup
|
|
300
|
-
},
|
|
301
|
-
isAppWebview: params.isAppWebview
|
|
302
|
-
});
|
|
303
|
-
case 3:
|
|
304
|
-
_context.next = 9;
|
|
305
|
-
break;
|
|
306
|
-
case 5:
|
|
307
|
-
_context.prev = 5;
|
|
308
|
-
_context.t0 = _context["catch"](0);
|
|
309
|
-
this.core.getServiceProvider().getService('EventCenter').emit(EVENT.eventCallback.name, {
|
|
310
|
-
code: eventCodeEnum.SDK_CREATEPAYMENT_PARAMETER_ERROR,
|
|
311
|
-
message: (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || 'Initialization parameter exception.'
|
|
312
|
-
});
|
|
313
|
-
this.core.destroy();
|
|
314
|
-
case 9:
|
|
315
|
-
case "end":
|
|
316
|
-
return _context.stop();
|
|
317
|
-
}
|
|
318
|
-
}, _callee, this, [[0, 5]]);
|
|
319
|
-
}));
|
|
320
|
-
function createComponent(_x) {
|
|
321
|
-
return _createComponent.apply(this, arguments);
|
|
322
|
-
}
|
|
323
|
-
return createComponent;
|
|
324
|
-
}()
|
|
325
|
-
}, {
|
|
326
|
-
key: "unmount",
|
|
327
|
-
value: function unmount() {
|
|
328
|
-
this.core.destroy();
|
|
329
|
-
}
|
|
330
|
-
}], [{
|
|
331
|
-
key: "preload",
|
|
332
|
-
value: function preload() {
|
|
333
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
334
|
-
securityRegion: 'SG',
|
|
335
|
-
environment: 'prod'
|
|
336
|
-
};
|
|
337
|
-
PreloadHelper.preloadWebApp(ProductSceneEnum.AUTO_DEBIT, PaymentMethodCategoryTypeEnum.WALLET, options.environment);
|
|
338
|
-
PreloadHelper.preloadSecuritySDK(ProductSceneEnum.AUTO_DEBIT, options.securityRegion);
|
|
339
|
-
}
|
|
340
|
-
}]);
|
|
341
|
-
return AMSAutoDebit;
|
|
342
|
-
}();
|
|
343
23
|
export default AMSCheckout;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AMSCashierPayment, AMSEasyPay, AMSElement } from '../main';
|
|
2
|
+
import { EConstructorName } from './constant';
|
|
3
|
+
export declare function createBaseProxy<T>(constructorName: EConstructorName.AMSCashierPayment): typeof AMSCashierPayment;
|
|
4
|
+
export declare function createBaseProxy<T>(constructorName: EConstructorName.AMSEasyPay): typeof AMSEasyPay;
|
|
5
|
+
export declare function createBaseProxy<T>(constructorName: EConstructorName.AMSElement): typeof AMSElement;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
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; }
|
|
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
|
+
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); }
|
|
14
|
+
/**
|
|
15
|
+
* Proxy代理层
|
|
16
|
+
* **/
|
|
17
|
+
import ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';
|
|
18
|
+
import { instanceApiMap } from "./constant";
|
|
19
|
+
import { supportsProxy } from "./utils/common";
|
|
20
|
+
import { setDebugContext } from "./utils/debugger";
|
|
21
|
+
import { loadSdk, newActualInstance } from "./utils/loadSDK";
|
|
22
|
+
import { logger } from "./utils/logger";
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line
|
|
31
|
+
export function createBaseProxy(constructorName) {
|
|
32
|
+
var _newProxyInstance = function _newProxyInstance(self) {
|
|
33
|
+
return new Proxy(self, {
|
|
34
|
+
get: function get(target, prop) {
|
|
35
|
+
// 如果是内部属性或方法,直接返回
|
|
36
|
+
if (prop in target || _typeof(prop) === 'symbol') {
|
|
37
|
+
return target[prop];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 返回一个代理方法
|
|
41
|
+
return function () {
|
|
42
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
|
+
args[_key] = arguments[_key];
|
|
44
|
+
}
|
|
45
|
+
// 已存在真实实例,直接调用
|
|
46
|
+
if (self.hasActualInstance && self.actualInstance) {
|
|
47
|
+
var _self$actualInstance;
|
|
48
|
+
return (_self$actualInstance = self.actualInstance)[prop].apply(_self$actualInstance, args);
|
|
49
|
+
} else {
|
|
50
|
+
// SDK未加载,记录调用
|
|
51
|
+
return new Promise(function (resolve, reject) {
|
|
52
|
+
self.pendingCalls.push({
|
|
53
|
+
method: prop,
|
|
54
|
+
args: args,
|
|
55
|
+
resolve: resolve,
|
|
56
|
+
reject: reject
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
var _newProxyInstanceWithPolyfill = function _newProxyInstanceWithPolyfill(self) {
|
|
65
|
+
var proxyConstructor = ProxyPolyfillBuilder();
|
|
66
|
+
|
|
67
|
+
// 创建一个只读,不可调用,不可枚举的临时api,用于被proxyPolyfill捕获
|
|
68
|
+
var CAPTURED__API_TEMP_VALUE = Symbol('CAPTURED__API_TEMP_VALUE');
|
|
69
|
+
var needCapturedApis = instanceApiMap[constructorName];
|
|
70
|
+
needCapturedApis.forEach(function (api) {
|
|
71
|
+
Object.defineProperty(self, api, {
|
|
72
|
+
value: CAPTURED__API_TEMP_VALUE,
|
|
73
|
+
writable: false,
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: false
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return new proxyConstructor(self, {
|
|
79
|
+
get: function get(target, prop) {
|
|
80
|
+
var proxyFunc = function proxyFunc() {
|
|
81
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
82
|
+
args[_key2] = arguments[_key2];
|
|
83
|
+
}
|
|
84
|
+
// 已存在真实实例,直接调用
|
|
85
|
+
if (self.hasActualInstance && self.actualInstance) {
|
|
86
|
+
var _self$actualInstance2;
|
|
87
|
+
return (_self$actualInstance2 = self.actualInstance)[prop].apply(_self$actualInstance2, args);
|
|
88
|
+
} else {
|
|
89
|
+
// SDK未加载,记录调用
|
|
90
|
+
return new Promise(function (resolve, reject) {
|
|
91
|
+
self.pendingCalls.push({
|
|
92
|
+
method: prop,
|
|
93
|
+
args: args,
|
|
94
|
+
resolve: resolve,
|
|
95
|
+
reject: reject
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// 如果是需要代理的API 则返回一个代理方法
|
|
102
|
+
if ((target === null || target === void 0 ? void 0 : target[prop]) === CAPTURED__API_TEMP_VALUE) {
|
|
103
|
+
return proxyFunc;
|
|
104
|
+
}
|
|
105
|
+
// 如果是无需被代理的内部属性或方法,直接返回
|
|
106
|
+
if (prop in target || _typeof(prop) === 'symbol') {
|
|
107
|
+
return target[prop];
|
|
108
|
+
}
|
|
109
|
+
// 兜底
|
|
110
|
+
return proxyFunc;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
var BaseProxy = /*#__PURE__*/function () {
|
|
115
|
+
// 返回代理实例对象
|
|
116
|
+
function BaseProxy(newProps, debugProps) {
|
|
117
|
+
_classCallCheck(this, BaseProxy);
|
|
118
|
+
_defineProperty(this, "hasActualInstance", false);
|
|
119
|
+
_defineProperty(this, "pendingCalls", []);
|
|
120
|
+
_defineProperty(this, "actualInstance", null);
|
|
121
|
+
_defineProperty(this, "proxyInstance", null);
|
|
122
|
+
_defineProperty(this, "startTime", 0);
|
|
123
|
+
this.startTime = Date.now();
|
|
124
|
+
|
|
125
|
+
// 初始化debug参数
|
|
126
|
+
setDebugContext(debugProps);
|
|
127
|
+
// 创建代理实例
|
|
128
|
+
this.proxyInstance = this.newProxyInstance();
|
|
129
|
+
// 加载sdk并创建真实实例
|
|
130
|
+
this.loadSDKAndCreateInstance(constructorName, newProps);
|
|
131
|
+
logger.logInfo({
|
|
132
|
+
title: 'create_proxy_instance_success'
|
|
133
|
+
});
|
|
134
|
+
return this.proxyInstance;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 初始化loader并开始加载sdk 创建实例,并执行所有待处理的调用
|
|
138
|
+
_createClass(BaseProxy, [{
|
|
139
|
+
key: "loadSDKAndCreateInstance",
|
|
140
|
+
value: function loadSDKAndCreateInstance(constructorName, newProps) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
loadSdk().then(function () {
|
|
143
|
+
var actualInstance = newActualInstance(constructorName, newProps);
|
|
144
|
+
|
|
145
|
+
// 从newProxy到初始化真实sdk实例花费时间
|
|
146
|
+
//TODO 最好尝试发送给web应用层进行上报
|
|
147
|
+
logger.logInfo({
|
|
148
|
+
title: 'report_customized_performance_m5'
|
|
149
|
+
}, {
|
|
150
|
+
m5: Date.now() - _this.startTime
|
|
151
|
+
});
|
|
152
|
+
logger.logInfo({
|
|
153
|
+
title: 'create_actual_instance_success'
|
|
154
|
+
}, {
|
|
155
|
+
constructorName: constructorName
|
|
156
|
+
});
|
|
157
|
+
try {
|
|
158
|
+
_this.actualInstance = actualInstance;
|
|
159
|
+
_this.hasActualInstance = true;
|
|
160
|
+
_this.executePendingCalls();
|
|
161
|
+
} catch (error) {
|
|
162
|
+
logger.logError({
|
|
163
|
+
title: 'create_actual_instance_error'
|
|
164
|
+
}, {
|
|
165
|
+
errorMessage: error,
|
|
166
|
+
constructorName: constructorName
|
|
167
|
+
});
|
|
168
|
+
_this.rejectPendingCalls(error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 创建代理实例
|
|
174
|
+
}, {
|
|
175
|
+
key: "newProxyInstance",
|
|
176
|
+
value: function newProxyInstance() {
|
|
177
|
+
try {
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
179
|
+
var self = this;
|
|
180
|
+
|
|
181
|
+
// 如果浏览器不支持Proxy,则使用Polyfill降级 https://github.com/GoogleChrome/proxy-polyfill,
|
|
182
|
+
// 注意: Polyfill降级方案需要预先定义需要捕获的api。
|
|
183
|
+
if (supportsProxy()) {
|
|
184
|
+
return _newProxyInstance(self);
|
|
185
|
+
} else {
|
|
186
|
+
logger.logInfo({
|
|
187
|
+
title: 'proxy_api_not_support'
|
|
188
|
+
});
|
|
189
|
+
return _newProxyInstanceWithPolyfill(self);
|
|
190
|
+
}
|
|
191
|
+
} catch (e) {
|
|
192
|
+
logger.logError({
|
|
193
|
+
title: 'create_proxy_instance_error'
|
|
194
|
+
}, {
|
|
195
|
+
errorMessage: e,
|
|
196
|
+
constructorName: constructorName
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 执行所有待处理的调用
|
|
202
|
+
}, {
|
|
203
|
+
key: "executePendingCalls",
|
|
204
|
+
value: function executePendingCalls() {
|
|
205
|
+
while (this.pendingCalls.length > 0) {
|
|
206
|
+
if (!this.actualInstance) return;
|
|
207
|
+
var pendingCall = this.pendingCalls.shift();
|
|
208
|
+
if (!pendingCall) return;
|
|
209
|
+
var method = pendingCall.method,
|
|
210
|
+
args = pendingCall.args,
|
|
211
|
+
resolve = pendingCall.resolve,
|
|
212
|
+
reject = pendingCall.reject;
|
|
213
|
+
try {
|
|
214
|
+
var _this$actualInstance;
|
|
215
|
+
var result = (_this$actualInstance = this.actualInstance)[method].apply(_this$actualInstance, _toConsumableArray(args));
|
|
216
|
+
resolve(result);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
logger.logError({
|
|
219
|
+
title: 'call_pending_method_error'
|
|
220
|
+
}, {
|
|
221
|
+
errorMessage: error,
|
|
222
|
+
constructorName: constructorName,
|
|
223
|
+
method: method
|
|
224
|
+
});
|
|
225
|
+
reject(error);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// 拒绝所有待处理的调用
|
|
230
|
+
}, {
|
|
231
|
+
key: "rejectPendingCalls",
|
|
232
|
+
value: function rejectPendingCalls(error) {
|
|
233
|
+
while (this.pendingCalls.length > 0) {
|
|
234
|
+
var pendingCall = this.pendingCalls.shift();
|
|
235
|
+
if (!pendingCall) return;
|
|
236
|
+
var reject = pendingCall.reject;
|
|
237
|
+
reject(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}]);
|
|
241
|
+
return BaseProxy;
|
|
242
|
+
}();
|
|
243
|
+
return BaseProxy;
|
|
244
|
+
}
|