@alipay/ams-checkout 0.0.1779094014-dev.0 → 0.0.1779094014-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.
Files changed (37) hide show
  1. package/ams-checkout.js +4 -3
  2. package/dist/ams-checkout.min.js +2 -1
  3. package/dist/ams-checkout.min.js.map +1 -0
  4. package/esm/constant/element.d.ts +2 -1
  5. package/esm/constant/element.js +1 -0
  6. package/esm/core/component/element/elementController/index.d.ts +3 -3
  7. package/esm/core/component/element/index.d.ts +1 -1
  8. package/esm/core/component/element/index.js +11 -1
  9. package/esm/core/component/element/modernElementController/adapter.d.ts +19 -0
  10. package/esm/core/component/element/modernElementController/adapter.js +74 -0
  11. package/esm/core/component/element/modernElementController/index.d.ts +80 -0
  12. package/esm/core/component/element/modernElementController/index.js +679 -0
  13. package/esm/core/component/element/type.d.ts +10 -0
  14. package/esm/foundation/service/event-center.js +1 -1
  15. package/esm/modern/index.js +1 -1
  16. package/esm/modern/oneapi/iexpfront/PaymentSessionService.d.ts +23 -0
  17. package/esm/modern/oneapi/iexpfront/PaymentSessionService.js +55 -0
  18. package/esm/modern/oneapi/iexpfront/definitions.d.ts +3656 -0
  19. package/esm/modern/oneapi/iexpfront/definitions.js +1 -0
  20. package/esm/modern/tools/AntomSDKError.d.ts +47 -0
  21. package/esm/modern/tools/AntomSDKError.js +47 -0
  22. package/esm/modern/tools/buildPageUrl.d.ts +4 -0
  23. package/esm/modern/tools/buildPageUrl.js +19 -0
  24. package/esm/modern/tools/getDevReqConfig.d.ts +2 -0
  25. package/esm/modern/tools/getDevReqConfig.js +16 -0
  26. package/esm/modern/tools/getLocaleFromRenderData.d.ts +6 -0
  27. package/esm/modern/tools/getLocaleFromRenderData.js +20 -0
  28. package/esm/modern/tools/getMetaData.d.ts +102 -0
  29. package/esm/modern/tools/getMetaData.js +7 -0
  30. package/esm/modern/tools/openModal.d.ts +20 -0
  31. package/esm/modern/tools/openModal.js +221 -0
  32. package/esm/types/index.d.ts +1 -0
  33. package/package.json +1 -1
  34. package/types.d.ts +2 -149
  35. package/types.untrimmed.d.ts +2 -152
  36. package/esm/modern/stageName.d.ts +0 -3
  37. package/esm/modern/stageName.js +0 -1
@@ -0,0 +1,679 @@
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 _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; }
5
+ 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); } }
6
+ 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); }); }; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ 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); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
14
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
15
+ 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); }
16
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
+ 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); }; }
18
+ 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); }
19
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
20
+ 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; } }
21
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
+ import { MessageType } from '@antintl/opensdk-core';
23
+ import { SDKBridge } from '@antintl/opensdk-bridge';
24
+ import { request, parseHostSign } from '@antintl/antom-toolset';
25
+ import { device } from "../../../../util";
26
+ import { openModal } from "../../../../modern/tools/openModal";
27
+ import { sdkQuery } from "../../../../modern/oneapi/iexpfront/PaymentSessionService";
28
+ import { getLocaleFromRenderData } from "../../../../modern/tools/getLocaleFromRenderData";
29
+ import { getDevReqConfig } from "../../../../modern/tools/getDevReqConfig";
30
+ import { EventCallbackCode } from "../type";
31
+ import { adaptSubmitResult, adaptErrorToEventCallback, adaptAppearance } from "./adapter";
32
+ import { getMetaData } from "../../../../modern/tools/getMetaData";
33
+ import { debugError, debug } from '@antintl/opensdk-core';
34
+ import { buildPageUrl } from "../../../../modern/tools/buildPageUrl";
35
+ import { AntomSDKError } from "../../../../modern/tools/AntomSDKError";
36
+ var MOUNT_TIMEOUT = 16000;
37
+
38
+ /**
39
+ * HostSDKBridge 扩展 SDKBridge,暴露 setTarget 方法供 HOST 模式使用
40
+ */
41
+ var HostSDKBridge = /*#__PURE__*/function (_SDKBridge) {
42
+ _inherits(HostSDKBridge, _SDKBridge);
43
+ var _super = _createSuper(HostSDKBridge);
44
+ function HostSDKBridge(mode, scope) {
45
+ _classCallCheck(this, HostSDKBridge);
46
+ return _super.call(this, mode, scope);
47
+ }
48
+
49
+ // 暴露 protected 的 setTarget 方法
50
+ _createClass(HostSDKBridge, [{
51
+ key: "setTargetWindow",
52
+ value: function setTargetWindow(window) {
53
+ this.setTarget(window);
54
+ }
55
+ }, {
56
+ key: "setDebugCallback",
57
+ value: function setDebugCallback() {
58
+ var _get2;
59
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
60
+ args[_key] = arguments[_key];
61
+ }
62
+ (_get2 = _get(_getPrototypeOf(HostSDKBridge.prototype), "setDebugCallback", this)).call.apply(_get2, [this].concat(args));
63
+ }
64
+ }]);
65
+ return HostSDKBridge;
66
+ }(SDKBridge);
67
+ /**
68
+ * AMSElement 特有的消息类型(非标准 MessageType,webapp 需配合实现)
69
+ * 使用索引签名兼容,避免 as any
70
+ */
71
+ var AMSMessageType = {
72
+ VALIDATE: 'OPENSDK@VALIDATE',
73
+ VALIDATE_REPLY: 'OPENSDK@VALIDATE_REPLY'
74
+ };
75
+
76
+ /**
77
+ * ModernElementController 使用 opensdk-core 的 HostBridge 实现新架构通信。
78
+ *
79
+ * Mount 流程(正确):
80
+ * 1. setup() — 解析 sessionData 获取 metaData,准备 HANDSHAKE 配置
81
+ * 2. 创建 iframe,设置 src
82
+ * 3. 将 iframe 添加到容器
83
+ * 4. 监听 READY_HANDSHAKE → setTarget(iframe.contentWindow) → send(HANDSHAKE, mergedConfig)
84
+ * 5. 等待 HANDSHAKE_ACK → 设置 status = 'ready'
85
+ * 6. ready 后发送缓存的消息
86
+ */
87
+ export var ModernElementController = /*#__PURE__*/function () {
88
+ function ModernElementController(options) {
89
+ _classCallCheck(this, ModernElementController);
90
+ _defineProperty(this, "options", void 0);
91
+ _defineProperty(this, "bridge", void 0);
92
+ _defineProperty(this, "iframe", null);
93
+ _defineProperty(this, "status", 'initialized');
94
+ _defineProperty(this, "eventListeners", new Map());
95
+ _defineProperty(this, "cachedSend", []);
96
+ // Modal 相关资源
97
+ _defineProperty(this, "modalIframe", null);
98
+ _defineProperty(this, "modalBridge", null);
99
+ _defineProperty(this, "modalDestroy", null);
100
+ _defineProperty(this, "_closeConfirmResolve", null);
101
+ this.options = options;
102
+ this.bridge = new HostSDKBridge('HOST', 'payment');
103
+ this.bridge.setDebugCallback(function (msg, direction) {
104
+ if (msg.type.endsWith(MessageType.UPDATE_CONFIG) || msg.type.endsWith(MessageType.HEIGHT_UPDATE)) {
105
+ return;
106
+ }
107
+ if (msg.type.endsWith(MessageType.MESSAGE)) {
108
+ var _msg$payload, _msg$payload2;
109
+ debug((_msg$payload = msg.payload) === null || _msg$payload === void 0 ? void 0 : _msg$payload.type, 'APP_RUNTIME', msg.type, (_msg$payload2 = msg.payload) === null || _msg$payload2 === void 0 ? void 0 : _msg$payload2.message);
110
+ } else if (msg.type.endsWith(MessageType.ERROR) && direction === 'IN') {
111
+ debugError(msg.payload);
112
+ } else {
113
+ debug('INFO', direction === 'OUT' ? 'SDK_INTERNAL' : 'APP_RUNTIME', msg.type, msg.payload);
114
+ }
115
+ });
116
+ }
117
+ _createClass(ModernElementController, [{
118
+ key: "mount",
119
+ value: function () {
120
+ var _mount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(renderOptions, sdkSelector) {
121
+ var _this$options$loading, _this$options$loading2;
122
+ var container, _this$options, _this$options$onEvent, _this$options$loading3, _this$options$loading4, setupConfig, iframeUrl, _this$options$loading5, _this$options$loading6, _this$options2, _this$options2$onEven, errorResult;
123
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
124
+ while (1) switch (_context.prev = _context.next) {
125
+ case 0:
126
+ container = document.querySelector(sdkSelector);
127
+ if (container) {
128
+ _context.next = 4;
129
+ break;
130
+ }
131
+ (_this$options = this.options) === null || _this$options === void 0 || (_this$options$onEvent = _this$options.onEventCallback) === null || _this$options$onEvent === void 0 || _this$options$onEvent.call(_this$options, {
132
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
133
+ message: "Element with selector ".concat(sdkSelector, " not found.")
134
+ });
135
+ return _context.abrupt("return", {
136
+ error: {
137
+ code: 'PARAM_INVALID',
138
+ message: "selector not found"
139
+ }
140
+ });
141
+ case 4:
142
+ (_this$options$loading = this.options.loading) === null || _this$options$loading === void 0 || (_this$options$loading2 = _this$options$loading.onStartLoading) === null || _this$options$loading2 === void 0 || _this$options$loading2.call(_this$options$loading);
143
+ this.status = 'mounting';
144
+ _context.prev = 6;
145
+ _context.next = 9;
146
+ return this.setup(renderOptions);
147
+ case 9:
148
+ setupConfig = _context.sent;
149
+ console.log('step1: setupConfig', setupConfig);
150
+
151
+ // 2. 创建 iframe,设置 src
152
+ iframeUrl = this.buildIframeUrl();
153
+ console.log('step2: iframeUrl', iframeUrl, this.options.environment);
154
+ this.iframe = document.createElement('iframe');
155
+ this.iframe.src = iframeUrl;
156
+ this.iframe.style.width = '100%';
157
+ this.iframe.style.border = 'none';
158
+ this.iframe.style.height = '0';
159
+ this.iframe.style.transition = 'height 0.3s ease';
160
+
161
+ // 3. 将 iframe 添加到容器
162
+ console.log('step3: iframe added to container');
163
+ container.appendChild(this.iframe);
164
+
165
+ // 4-5. 执行握手流程
166
+ console.log('step4-5: handshake completed');
167
+ _context.next = 24;
168
+ return this.performHandshake(setupConfig);
169
+ case 24:
170
+ console.log('step6: events bound');
171
+ // 6. 绑定持续监听的事件
172
+ this.bindBridgeEvents();
173
+ this.status = 'ready';
174
+ this.flushCachedMessages();
175
+ (_this$options$loading3 = this.options.loading) === null || _this$options$loading3 === void 0 || (_this$options$loading4 = _this$options$loading3.onEndLoading) === null || _this$options$loading4 === void 0 || _this$options$loading4.call(_this$options$loading3);
176
+ return _context.abrupt("return", {});
177
+ case 32:
178
+ _context.prev = 32;
179
+ _context.t0 = _context["catch"](6);
180
+ (_this$options$loading5 = this.options.loading) === null || _this$options$loading5 === void 0 || (_this$options$loading6 = _this$options$loading5.onEndLoading) === null || _this$options$loading6 === void 0 || _this$options$loading6.call(_this$options$loading5);
181
+ this.cleanup();
182
+ errorResult = {
183
+ code: _context.t0.code || 'UNKNOWN',
184
+ message: _context.t0.message || ''
185
+ };
186
+ (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2$onEven = _this$options2.onEventCallback) === null || _this$options2$onEven === void 0 || _this$options2$onEven.call(_this$options2, errorResult);
187
+ return _context.abrupt("return", {
188
+ error: errorResult
189
+ });
190
+ case 39:
191
+ case "end":
192
+ return _context.stop();
193
+ }
194
+ }, _callee, this, [[6, 32]]);
195
+ }));
196
+ function mount(_x, _x2) {
197
+ return _mount.apply(this, arguments);
198
+ }
199
+ return mount;
200
+ }()
201
+ /**
202
+ * setup() — 解析 sessionData 获取 metaData,发起 sdkQuery 获取渲染数据,准备 HANDSHAKE 配置
203
+ *
204
+ * 完整实现:
205
+ * 1. 解析 sessionData 获取 paymentSessionConfig
206
+ * 2. 初始化 request 全局配置(hostSign, env, sdkVersion)
207
+ * 3. 调用 sdkQuery 获取 renderData
208
+ * 4. 处理请求错误,将错误信息放入 renderDataError(不阻塞 mount 流程)
209
+ * 5. 从 renderData 中提取 preferredLocale
210
+ */
211
+ }, {
212
+ key: "setup",
213
+ value: (function () {
214
+ var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderOptions) {
215
+ var _result$data;
216
+ var sessionData, parseData, result, preferredLocale, locale;
217
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
218
+ while (1) switch (_context2.prev = _context2.next) {
219
+ case 0:
220
+ sessionData = this.options.sessionData;
221
+ parseData = getMetaData(sessionData); // 初始化 request 全局配置,使 sdkQuery 能正确发起请求
222
+ request.setGlobalOptions({
223
+ hostSign: parseHostSign(sessionData),
224
+ env: this.options.environment,
225
+ sdkVersion: "0.0.1779094014-dev.2" || ''
226
+ });
227
+
228
+ // 调用 sdkQuery 获取渲染数据,参照 VaultingElement.setup()
229
+ _context2.next = 5;
230
+ return sdkQuery({
231
+ extParams: {
232
+ isUserPreferredLocale: true
233
+ },
234
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
235
+ paymentSessionData: sessionData
236
+ }).then(function (res) {
237
+ return {
238
+ data: res,
239
+ error: undefined
240
+ };
241
+ }).catch(function (e) {
242
+ var _AntomSDKError$unific;
243
+ return {
244
+ error: (_AntomSDKError$unific = AntomSDKError.unificationError(e)) === null || _AntomSDKError$unific === void 0 ? void 0 : _AntomSDKError$unific.toJSON(),
245
+ data: undefined
246
+ };
247
+ });
248
+ case 5:
249
+ result = _context2.sent;
250
+ // 从 renderData 中提取 preferredLocale
251
+ preferredLocale = getLocaleFromRenderData(result.data);
252
+ locale = preferredLocale || this.options.locale;
253
+ return _context2.abrupt("return", {
254
+ sessionData: sessionData,
255
+ environment: this.options.environment,
256
+ locale: locale,
257
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
258
+ appearance: adaptAppearance((renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.appearance) || this.options.appearance),
259
+ // 新增字段
260
+ renderData: result.data,
261
+ renderDataError: result.error,
262
+ sdkVersion: "0.0.1779094014-dev.2" || '',
263
+ merchantId: ((_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.merchantId) || '',
264
+ env: this.options.environment || 'prod',
265
+ _requestConfig: _objectSpread({
266
+ env: this.options.environment || 'prod'
267
+ }, getDevReqConfig())
268
+ });
269
+ case 9:
270
+ case "end":
271
+ return _context2.stop();
272
+ }
273
+ }, _callee2, this);
274
+ }));
275
+ function setup(_x3) {
276
+ return _setup.apply(this, arguments);
277
+ }
278
+ return setup;
279
+ }()
280
+ /**
281
+ * 执行握手流程:
282
+ * - 监听 READY_HANDSHAKE → setTarget → send(HANDSHAKE, mergedConfig)
283
+ * - 等待 HANDSHAKE_ACK → resolve
284
+ */
285
+ )
286
+ }, {
287
+ key: "performHandshake",
288
+ value: (function () {
289
+ var _performHandshake = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(setupConfig) {
290
+ var _this = this;
291
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
292
+ while (1) switch (_context3.prev = _context3.next) {
293
+ case 0:
294
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
295
+ var timer = setTimeout(function () {
296
+ reject({
297
+ code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
298
+ message: 'Mount timeout'
299
+ });
300
+ }, MOUNT_TIMEOUT);
301
+
302
+ // 监听 HEIGHT_UPDATE(只需要注册一次,放在握手前避免丢失早期消息)
303
+ _this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
304
+ console.log(height, 'HEIGHT_UPDATE');
305
+ if (_this.iframe) _this.iframe.style.height = "".concat(height, "px");
306
+ });
307
+
308
+ // 4. 监听 READY_HANDSHAKE → setTarget → send(HANDSHAKE, mergedConfig)
309
+ _this.bridge.once(MessageType.READY_HANDSHAKE, function () {
310
+ var _this$iframe;
311
+ console.log('READY_HANDSHAKE');
312
+ if (!((_this$iframe = _this.iframe) !== null && _this$iframe !== void 0 && _this$iframe.contentWindow)) {
313
+ clearTimeout(timer);
314
+ reject({
315
+ code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
316
+ message: 'Iframe contentWindow not available'
317
+ });
318
+ return;
319
+ }
320
+ _this.bridge.setTargetWindow(_this.iframe.contentWindow);
321
+
322
+ // 设置安全源
323
+ try {
324
+ var iframeOrigin = new URL(_this.iframe.src).origin;
325
+ if (iframeOrigin && iframeOrigin !== 'null') {
326
+ _this.bridge.setOrigin(iframeOrigin);
327
+ }
328
+ } catch (_unused) {
329
+ // URL 解析失败时保持默认 origin
330
+ }
331
+
332
+ // HANDSHAKE payload 包含 setup() 返回的完整配置
333
+ _this.bridge.send(MessageType.HANDSHAKE, setupConfig);
334
+ });
335
+
336
+ // 5. 等待 HANDSHAKE_ACK
337
+ _this.bridge.once(MessageType.HANDSHAKE_ACK, function () {
338
+ clearTimeout(timer);
339
+ resolve();
340
+ });
341
+ }));
342
+ case 1:
343
+ case "end":
344
+ return _context3.stop();
345
+ }
346
+ }, _callee3);
347
+ }));
348
+ function performHandshake(_x4) {
349
+ return _performHandshake.apply(this, arguments);
350
+ }
351
+ return performHandshake;
352
+ }()
353
+ /**
354
+ * 绑定持续监听的 bridge 事件
355
+ */
356
+ )
357
+ }, {
358
+ key: "bindBridgeEvents",
359
+ value: function bindBridgeEvents() {
360
+ var _this2 = this;
361
+ this.bridge.on(MessageType.ERROR, function (payload) {
362
+ var _this2$options, _this2$options$onEven;
363
+ (_this2$options = _this2.options) === null || _this2$options === void 0 || (_this2$options$onEven = _this2$options.onEventCallback) === null || _this2$options$onEven === void 0 || _this2$options$onEven.call(_this2$options, adaptErrorToEventCallback(payload));
364
+ });
365
+ this.bridge.on(MessageType.REDIRECT, function (payload) {
366
+ var url = payload.url,
367
+ mode = payload.mode;
368
+ if (mode === 'replace') {
369
+ window.location.replace(url);
370
+ } else {
371
+ window.location.href = url;
372
+ }
373
+ });
374
+ this.bridge.on(MessageType.OPEN_MODAL, function (payload) {
375
+ _this2.handleOpenModal(payload);
376
+ });
377
+ this.bridge.on(MessageType.CLOSE_MODAL, function () {
378
+ _this2.handleCloseModal();
379
+ });
380
+ }
381
+ }, {
382
+ key: "submitPayment",
383
+ value: function () {
384
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
385
+ var _this$options$loading7,
386
+ _this$options$loading8,
387
+ _this3 = this;
388
+ var result, _this$options$loading9, _this$options$loading10;
389
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
390
+ while (1) switch (_context4.prev = _context4.next) {
391
+ case 0:
392
+ if (!(this.status !== 'ready')) {
393
+ _context4.next = 2;
394
+ break;
395
+ }
396
+ return _context4.abrupt("return", {
397
+ status: 'FAIL',
398
+ error: {
399
+ code: 'UI_STATE_ERROR',
400
+ message: 'not ready'
401
+ }
402
+ });
403
+ case 2:
404
+ (_this$options$loading7 = this.options.loading) === null || _this$options$loading7 === void 0 || (_this$options$loading8 = _this$options$loading7.onStartLoading) === null || _this$options$loading8 === void 0 || _this$options$loading8.call(_this$options$loading7);
405
+ _context4.prev = 3;
406
+ this.send(MessageType.SUBMIT, params);
407
+ _context4.next = 7;
408
+ return new Promise(function (resolve) {
409
+ _this3.bridge.once(MessageType.SUBMIT_REPLY, resolve);
410
+ });
411
+ case 7:
412
+ result = _context4.sent;
413
+ return _context4.abrupt("return", adaptSubmitResult(result));
414
+ case 9:
415
+ _context4.prev = 9;
416
+ (_this$options$loading9 = this.options.loading) === null || _this$options$loading9 === void 0 || (_this$options$loading10 = _this$options$loading9.onEndLoading) === null || _this$options$loading10 === void 0 || _this$options$loading10.call(_this$options$loading9);
417
+ return _context4.finish(9);
418
+ case 12:
419
+ case "end":
420
+ return _context4.stop();
421
+ }
422
+ }, _callee4, this, [[3,, 9, 12]]);
423
+ }));
424
+ function submitPayment(_x5) {
425
+ return _submitPayment.apply(this, arguments);
426
+ }
427
+ return submitPayment;
428
+ }()
429
+ }, {
430
+ key: "validateFields",
431
+ value: function () {
432
+ var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
433
+ var _this4 = this;
434
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
435
+ while (1) switch (_context5.prev = _context5.next) {
436
+ case 0:
437
+ if (!(this.status !== 'ready')) {
438
+ _context5.next = 2;
439
+ break;
440
+ }
441
+ return _context5.abrupt("return", {
442
+ isValid: false
443
+ });
444
+ case 2:
445
+ this.send(AMSMessageType.VALIDATE);
446
+ return _context5.abrupt("return", new Promise(function (resolve) {
447
+ var timer = setTimeout(function () {
448
+ return resolve({
449
+ isValid: false
450
+ });
451
+ }, 15000);
452
+ _this4.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
453
+ clearTimeout(timer);
454
+ resolve(payload || {
455
+ isValid: false
456
+ });
457
+ });
458
+ }));
459
+ case 4:
460
+ case "end":
461
+ return _context5.stop();
462
+ }
463
+ }, _callee5, this);
464
+ }));
465
+ function validateFields() {
466
+ return _validateFields.apply(this, arguments);
467
+ }
468
+ return validateFields;
469
+ }()
470
+ }, {
471
+ key: "updatePayment",
472
+ value: function () {
473
+ var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(paymentSessionData) {
474
+ var parseData, merged;
475
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
476
+ while (1) switch (_context6.prev = _context6.next) {
477
+ case 0:
478
+ if (!(this.status !== 'ready')) {
479
+ _context6.next = 2;
480
+ break;
481
+ }
482
+ return _context6.abrupt("return", false);
483
+ case 2:
484
+ // 更新内部 sessionData
485
+ this.options.sessionData = paymentSessionData;
486
+ parseData = getMetaData(paymentSessionData);
487
+ merged = {
488
+ sessionData: paymentSessionData,
489
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
490
+ environment: this.options.environment,
491
+ locale: this.options.locale
492
+ };
493
+ this.bridge.send(MessageType.UPDATE_CONFIG, {
494
+ merged: merged,
495
+ updated: {
496
+ sessionData: paymentSessionData,
497
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig
498
+ }
499
+ });
500
+ return _context6.abrupt("return", true);
501
+ case 7:
502
+ case "end":
503
+ return _context6.stop();
504
+ }
505
+ }, _callee6, this);
506
+ }));
507
+ function updatePayment(_x6) {
508
+ return _updatePayment.apply(this, arguments);
509
+ }
510
+ return updatePayment;
511
+ }()
512
+ }, {
513
+ key: "on",
514
+ value: function on(event, callback) {
515
+ if (!this.eventListeners.has(event)) this.eventListeners.set(event, new Set());
516
+ this.eventListeners.get(event).add(callback);
517
+ this.bridge.on(event, callback);
518
+ }
519
+ }, {
520
+ key: "destroy",
521
+ value: function destroy() {
522
+ var _this$iframe2;
523
+ this.handleCloseModal();
524
+ this.bridge.destroy();
525
+ if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
526
+ this.iframe = null;
527
+ this.status = 'destroyed';
528
+ this.eventListeners.clear();
529
+ this.cachedSend = [];
530
+ }
531
+ }, {
532
+ key: "cleanup",
533
+ value: function cleanup() {
534
+ var _this$iframe3;
535
+ if ((_this$iframe3 = this.iframe) !== null && _this$iframe3 !== void 0 && _this$iframe3.parentNode) this.iframe.parentNode.removeChild(this.iframe);
536
+ this.iframe = null;
537
+ this.status = 'initialized';
538
+ this.cachedSend = [];
539
+ }
540
+
541
+ /**
542
+ * 带缓存的消息发送:当 status 不是 ready 时,缓存消息;ready 后由 flushCachedMessages 批量发送
543
+ */
544
+ }, {
545
+ key: "send",
546
+ value: function send(type, payload) {
547
+ if (this.status === 'destroyed') {
548
+ return;
549
+ }
550
+ if (this.status !== 'ready') {
551
+ this.cachedSend.push({
552
+ type: type,
553
+ payload: payload
554
+ });
555
+ return;
556
+ }
557
+ this.bridge.send(type, payload);
558
+ }
559
+
560
+ /**
561
+ * 批量发送缓存的消息
562
+ */
563
+ }, {
564
+ key: "flushCachedMessages",
565
+ value: function flushCachedMessages() {
566
+ var _this5 = this;
567
+ if (this.cachedSend.length > 0) {
568
+ this.cachedSend.forEach(function (_ref) {
569
+ var type = _ref.type,
570
+ payload = _ref.payload;
571
+ _this5.bridge.send(type, payload);
572
+ });
573
+ this.cachedSend = [];
574
+ }
575
+ }
576
+
577
+ /**
578
+ * 处理 webapp 请求打开 modal 弹窗
579
+ *
580
+ * 流程(参照 BaseFactory 桥接流程):
581
+ * 1. 调用 openModal 工具函数创建 modal DOM(overlay + modal + iframe + 动画 + close icon + loading)
582
+ * 2. 为 modal 创建独立的 HostBridge 用于通信
583
+ * 3. iframe 加载后 setTarget 到 modal iframe 的 contentWindow
584
+ * 4. 监听 modal 的 READY_HANDSHAKE → 发送配置消息
585
+ * 5. 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送
586
+ * 6. 如果 payload 有 closeConfirm,创建 MessageChannel port 用于确认关闭
587
+ */
588
+ }, {
589
+ key: "handleOpenModal",
590
+ value: function handleOpenModal(payload) {
591
+ var _this6 = this;
592
+ // 清理已存在的 modal
593
+ this.handleCloseModal();
594
+ var mode = device.isMobile ? 'mobile' : 'desktop';
595
+
596
+ // 为 modal 创建独立的 HostBridge 用于通信(scope 使用 payload 的 scope 或 'modal')
597
+ var modalBridge = this.modalBridge = new HostSDKBridge('HOST', payload.scope || 'modal');
598
+
599
+ // 处理 closeConfirm 的 MessageChannel
600
+ var messageChannel = payload.closeConfirm ? new MessageChannel() : null;
601
+
602
+ // 调用 openModal 工具函数创建 DOM(overlay + modal + iframe + 动画 + close icon + loading)
603
+ var _openModal = openModal({
604
+ url: payload.url,
605
+ mode: mode,
606
+ showClose: payload.showClose,
607
+ hideCloseWhenLoaded: payload.hideCloseWhenLoaded,
608
+ showLoading: payload.showLoading,
609
+ onClose: payload.closeConfirm ? function () {
610
+ return new Promise(function (resolve) {
611
+ // closeConfirm 时等待确认关闭(由 CLOSE_MODAL 消息触发 resolve)
612
+ _this6._closeConfirmResolve = resolve;
613
+ });
614
+ } : undefined
615
+ }),
616
+ iframe = _openModal.iframe,
617
+ destroy = _openModal.destroy;
618
+ this.modalIframe = iframe;
619
+ this.modalDestroy = destroy;
620
+
621
+ // 监听 modal 的 iframe load 事件
622
+ iframe.addEventListener('load', function () {
623
+ // 确保 target 已设置(如果 load 事件尚未触发,在此设置)
624
+ if (iframe.contentWindow) {
625
+ modalBridge.setTargetWindow(iframe.contentWindow);
626
+ try {
627
+ var iframeOrigin = new URL(iframe.src).origin;
628
+ if (iframeOrigin && iframeOrigin !== 'null') {
629
+ modalBridge.setOrigin(iframeOrigin);
630
+ }
631
+ } catch (_unused2) {
632
+ // URL 解析失败时保持默认 origin
633
+ }
634
+ }
635
+
636
+ // 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送给 modal
637
+ if (payload.appearance) {
638
+ modalBridge.send(MessageType.TRANSFER_MODAL_APPEARANCE, payload.appearance);
639
+ }
640
+
641
+ // 如果 payload 有 closeConfirm,创建 MessageChannel port 用于确认关闭
642
+ if (payload.closeConfirm && messageChannel) {
643
+ // 发送 port1 给 webapp(主 iframe)
644
+ _this6.bridge.send(MessageType.TRANSFER_APP_PORT, undefined, [messageChannel.port1]);
645
+ // 发送 port2 给 modal
646
+ modalBridge.send(MessageType.TRANSFER_MODAL_PORT, undefined, [messageChannel.port2]);
647
+ }
648
+ });
649
+ }
650
+
651
+ /**
652
+ * 销毁 modal bridge、调用 openModal 返回的 destroy 方法清理 modal DOM
653
+ */
654
+ }, {
655
+ key: "handleCloseModal",
656
+ value: function handleCloseModal() {
657
+ // 如果有等待中的 closeConfirm,resolve 它
658
+ if (this._closeConfirmResolve) {
659
+ this._closeConfirmResolve();
660
+ this._closeConfirmResolve = null;
661
+ }
662
+ if (this.modalBridge) {
663
+ this.modalBridge.destroy();
664
+ this.modalBridge = null;
665
+ }
666
+ if (this.modalDestroy) {
667
+ this.modalDestroy();
668
+ this.modalDestroy = null;
669
+ }
670
+ this.modalIframe = null;
671
+ }
672
+ }, {
673
+ key: "buildIframeUrl",
674
+ value: function buildIframeUrl() {
675
+ return buildPageUrl('/element_payment/index.html', true);
676
+ }
677
+ }]);
678
+ return ModernElementController;
679
+ }();