@alipay/ams-checkout 0.0.1767075519-dev.0 → 0.0.1767873844-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.
@@ -23,8 +23,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
23
23
  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; }
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
25
  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); }
26
- import { ServiceProvider } from "../../../../foundation/service";
27
- import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
28
26
  import { cleanMockup, removeRetentionPopup } from "../../../../component/component.popup.style";
29
27
  import { destroyModal } from "../../../../component/popupWindow.style";
30
28
  import { ERRORMESSAGE, EVENT, PROMISE_CALLBACK_CODE } from "../../../../constant";
@@ -34,14 +32,16 @@ import PaymentProcessor from "../../../../core/component/element/elementProcesso
34
32
  import { IElementStatus } from "../../../../foundation";
35
33
  import { AntomSDKCore } from "../../../../foundation/core";
36
34
  import { ElementProcessor } from "../../../../foundation/product-processor/element";
35
+ import { ServiceProvider } from "../../../../foundation/service";
36
+ import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
37
37
  import { ProductSceneEnum } from "../../../../types";
38
+ import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
38
39
  import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
39
40
  import { IContainerStatus } from "../elementContainerService/containerService";
40
41
  import { EventCenter as ElementEventCenter } from "../EventCenter/index";
41
42
  import { oneAccountUpdate, sdkActionUpdate } from "../mock";
42
43
  import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
43
44
  import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeStringify, showToast } from "../util";
44
- import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
45
45
  var TIMEOUT_DURATION = 10000;
46
46
  var ElementController = /*#__PURE__*/function () {
47
47
  function ElementController(options) {
@@ -89,13 +89,16 @@ var ElementController = /*#__PURE__*/function () {
89
89
  this.options = options;
90
90
  var _options = options;
91
91
  this.onStatusChangeCallback = _options === null || _options === void 0 ? void 0 : _options.onStatusChangeCallback;
92
+ // 初始化 this.elementContainer 的 status 为 INITING
92
93
  this.elementContainer = new AntomSDKCore();
93
94
  this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor());
95
+ // 初始化实例 id,监听 onRedirect 事件
94
96
  this.elementContainer.init(this.options, ProductSceneEnum.ELEMENT_PAYMENT);
95
97
  this.initService();
96
98
  this.elementContainerService = new ElementContainerService({
97
99
  instanceId: this.elementContainer.getInstanceId()
98
100
  });
101
+ // status 设置为 READY
99
102
  this.setControllerStatusOrView(IElementStatus.READY);
100
103
  this.elementEventCenter = new ElementEventCenter({
101
104
  logger: this.elementContainer.getServiceProvider().getService('Log')
@@ -205,6 +208,7 @@ var ElementController = /*#__PURE__*/function () {
205
208
  key: "initializeAndMountProcessor",
206
209
  value: function initializeAndMountProcessor(type, selector, options) {
207
210
  this.initElementProcessors(type);
211
+ // 创建 iframe,拉起应用页面,同时监听全局的数据更新和获取事件
208
212
  this.elementContainerService.mount({
209
213
  type: type,
210
214
  selector: selector,
@@ -241,6 +245,7 @@ var ElementController = /*#__PURE__*/function () {
241
245
  key: "mount",
242
246
  value: function mount(renderOptions, sdkSelector) {
243
247
  var _this2 = this;
248
+ // 此处的 id 是 sessionData && 分割的前3位
244
249
  var _convertPaymentSessio = convertPaymentSession(this.options.sessionData),
245
250
  sessionData = _convertPaymentSessio.id;
246
251
  var startEventId = this.elementEventCenter.registerEvent(EXPOSURE_API_EVENT.MOUNT, sessionData);
@@ -264,6 +269,7 @@ var ElementController = /*#__PURE__*/function () {
264
269
  return;
265
270
  }
266
271
  _this2.clearAndSetInitTimeout(readyCallback);
272
+ // 回调 loading 的 onStartLoading
267
273
  _this2.changeLoading(true);
268
274
  try {
269
275
  var startBizFlowData = {
@@ -272,10 +278,14 @@ var ElementController = /*#__PURE__*/function () {
272
278
  appendAliasContainerId: true
273
279
  })
274
280
  };
281
+ // status 设置为 IN_BIZ_FLOW
275
282
  _this2.setControllerStatusOrView(IElementStatus.IN_BIZ_FLOW);
276
283
  _this2.elementContainer.startBizFlow(startBizFlowData);
284
+ // 创建 iframe 加载应用页面
277
285
  _this2.initializeAndMountProcessor(renderOptions.type, sdkSelector, renderOptions);
286
+ // 监听应用页面 onLaunch 事件,请求 sdkAction.query 接口的数据,请求完成后处理数据异常情况或发送 renderComponent 事件及数据给应用层渲染页面内容
278
287
  _this2.sendRequestAndWaitWebLaunch(renderOptions, readyCallback);
288
+ // 监听事件
279
289
  _this2.addEventListener(readyCallback);
280
290
  _this2.serviceMap.EventCenter.addIFrame(_this2.elementContainerService.getContainerService(renderOptions.type).getContainerService().getWebApp());
281
291
  } catch (error) {
@@ -617,7 +627,10 @@ var ElementController = /*#__PURE__*/function () {
617
627
  return _context5.abrupt("return");
618
628
  case 7:
619
629
  _context5.next = 9;
620
- return Promise.all([containerService.createWebLaunchPromise(), this.elementProcessors[type].obtainData()]);
630
+ return Promise.all([containerService.createWebLaunchPromise(),
631
+ // 监听 onLaunch 事件
632
+ this.elementProcessors[type].obtainData() // 请求 sdkAction.query 的数据,connect 还会请求 account.query
633
+ ]);
621
634
  case 9:
622
635
  _yield$Promise$all = _context5.sent;
623
636
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
@@ -626,12 +639,15 @@ var ElementController = /*#__PURE__*/function () {
626
639
  this.serviceMap.Log.logInfo({
627
640
  title: 'sdk_event_webAppOnLaunch'
628
641
  });
642
+ // 应用页面加载完成且接口请求完成,状态设置为 READY
629
643
  containerService === null || containerService === void 0 || containerService.switchContainerStatus(IContainerStatus.READY);
644
+ // 处理接口数据异常情况,直接回调,结束流程
630
645
  errorResult = this.getErrorFromResponse(obtainDataResult);
631
646
  if (errorResult) {
632
- // 仅结束resove,传出回调码
647
+ // 仅结束resolve,传出回调码
633
648
  readyCallback(errorResult);
634
649
  }
650
+ // 页面加载和数据状态 READY 后,SDK 向应用层发送 renderComponent 事件,传递应用层渲染必须的数据
635
651
  if (this.areAllContainersReady()) {
636
652
  this.elementContainerService.getContainerServices().forEach(function (_, key) {
637
653
  _this5.sendReady(key, options);
@@ -1,5 +1,5 @@
1
- import { PaymentContext, SDKMetaData, Service } from '../../index';
2
1
  import { IoptionsParams } from '../../../types';
2
+ import { PaymentContext, SDKMetaData, Service } from '../../index';
3
3
  import { LogExtra, LogMetaData, LogPayload } from './types';
4
4
  /**
5
5
  * @author 谦彧 <zhangmian.zm@alipay.com>
@@ -8,10 +8,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
8
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
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
10
  import { EnvironmentEnum } from "../../../types";
11
- import { LogComplianceProcessor } from "./processor";
12
11
  import { isPC } from "../../../util";
13
- import { getStorageString, setStorageString } from "../../../util/storage";
14
12
  import { SPM_MAP } from "../../../util/spm-map";
13
+ import { getStorageString, setStorageString } from "../../../util/storage";
14
+ import { LogComplianceProcessor } from "./processor";
15
15
 
16
16
  /**
17
17
  * @author 谦彧 <zhangmian.zm@alipay.com>
@@ -185,14 +185,14 @@ export var LogService = /*#__PURE__*/function () {
185
185
  value: function loadScript(url, callback) {
186
186
  var _this3 = this;
187
187
  /*
188
- * 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
189
- * Message: Mismatched anonymous define() module
190
- * 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
191
- * 而宿主环境中已经存在匿名模块,导致报错。
192
- *
193
- * TODO: 所有通过window.iTracker调用的方法都需要判断
194
- * 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
195
- * */
188
+ * 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
189
+ * Message: Mismatched anonymous define() module
190
+ * 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
191
+ * 而宿主环境中已经存在匿名模块,导致报错。
192
+ *
193
+ * TODO: 所有通过window.iTracker调用的方法都需要判断
194
+ * 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
195
+ * */
196
196
  if (typeof window.define === 'function' && window.define.amd && typeof window.require === 'function') {
197
197
  var moduleId = 'antom_iTracker';
198
198
  try {
@@ -227,7 +227,12 @@ export var LogService = /*#__PURE__*/function () {
227
227
  script.onerror = function () {
228
228
  console.error("unable to load Antom script: ".concat(url));
229
229
  };
230
- document.body.appendChild(script);
230
+ // CDN 方式接入 sdk,执行时机可能在 body 创建之前
231
+ if (document.body) {
232
+ document.body.appendChild(script);
233
+ } else if (document.head) {
234
+ document.head.appendChild(script);
235
+ }
231
236
  }
232
237
  }, {
233
238
  key: "initTracker",
@@ -220,7 +220,12 @@ export var Logger = /*#__PURE__*/function () {
220
220
  script.onerror = function () {
221
221
  console.error("unable to load Antom script: ".concat(url));
222
222
  };
223
- document.body.appendChild(script);
223
+ // CDN 方式接入 sdk,执行时机可能在 body 创建之前
224
+ if (document.body) {
225
+ document.body.appendChild(script);
226
+ } else if (document.head) {
227
+ document.head.appendChild(script);
228
+ }
224
229
  }
225
230
  }, {
226
231
  key: "initTracker",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1767075519-dev.0",
3
+ "version": "0.0.1767873844-dev.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",