@alipay/ams-checkout 0.0.1705989903-dev.1 → 0.0.1708315090-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.
@@ -5,14 +5,19 @@ export declare const getComponentSign: (params: IpaymentSessionMetaData) => comp
5
5
  export declare const parseSessionData: (sessionData: string) => [IpaymentSessionMetaData, string];
6
6
  export declare class AMSComponent extends CoreInstance {
7
7
  _componentApp: ComponentApp;
8
+ channelType: componentSignEnum[];
9
+ productSceneVersion: string;
8
10
  constructor(options: IoptionsParams);
9
11
  private parameterInitAndCheck;
10
12
  private pluginAppendIframe;
13
+ private savePreviousChannel;
11
14
  /**
12
15
  * @description Create component application
13
16
  * @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
14
17
  */
15
18
  createComponent(params: IcreateComponent): Promise<void>;
19
+ preloadComponent(channelType: any, productSceneVersion: any): void;
20
+ clearPreloadIframe(): void;
16
21
  /**
17
22
  * @description Create and render components in the specified element area
18
23
  * @param params - The data source created by the component, necessary sessionData, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
@@ -30,7 +30,7 @@ import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
30
30
  import ComponentApp from "../../plugin/component";
31
31
  import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
32
  import { getOrSetStorageId, isPC } from "../../util";
33
- import { createIframeNode } from "../../util/createIframeNode";
33
+ import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
34
34
  import { getSecurityConfigStorageKey } from "../../util/security";
35
35
  import CoreInstance from "../instance/index";
36
36
  export var getComponentSign = function getComponentSign(params) {
@@ -106,8 +106,11 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
106
106
  _this = _super.call(this, options);
107
107
  // Instantiate the plug-in and set render
108
108
  _defineProperty(_assertThisInitialized(_this), "_componentApp", void 0);
109
+ _defineProperty(_assertThisInitialized(_this), "channelType", void 0);
110
+ _defineProperty(_assertThisInitialized(_this), "productSceneVersion", void 0);
109
111
  var ComponentPlugin = new ComponentApp();
110
112
  ComponentPlugin.setRender(createIframeNode);
113
+ ComponentPlugin.setPreloadRender(createPreloadIframeNode);
111
114
  // Register Cashier Application Plug in
112
115
  _this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
113
116
  _this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
@@ -146,6 +149,26 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
146
149
  return Promise.reject(error);
147
150
  }
148
151
  }
152
+ }, {
153
+ key: "savePreviousChannel",
154
+ value: function savePreviousChannel(iframeNodesParams) {
155
+ var _ref2 = iframeNodesParams || {},
156
+ _ref2$paymentSessionM = _ref2.paymentSessionMetaData.paymentSessionConfig,
157
+ _ref2$paymentSessionM2 = _ref2$paymentSessionM.productScene,
158
+ productScene = _ref2$paymentSessionM2 === void 0 ? '' : _ref2$paymentSessionM2,
159
+ _ref2$paymentSessionM3 = _ref2$paymentSessionM.paymentMethodCategoryType,
160
+ paymentMethodCategoryType = _ref2$paymentSessionM3 === void 0 ? '' : _ref2$paymentSessionM3,
161
+ _ref2$paymentSessionM4 = _ref2$paymentSessionM.productSceneVersion,
162
+ productSceneVersion = _ref2$paymentSessionM4 === void 0 ? '' : _ref2$paymentSessionM4;
163
+ var channelType = "".concat(productScene, "_").concat(paymentMethodCategoryType);
164
+ if (productScene && productSceneVersion) {
165
+ var previousChannel = {
166
+ channelType: channelType === componentSignEnum.VAULTING_CARD ? componentSignEnum.CASHIER_PAYMENT_CARD : channelType,
167
+ productSceneVersion: productSceneVersion
168
+ };
169
+ localStorage.setItem('previousChannel', JSON.stringify(previousChannel));
170
+ }
171
+ }
149
172
  /**
150
173
  * @description Create component application
151
174
  * @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
@@ -154,6 +177,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
154
177
  key: "createComponent",
155
178
  value: function createComponent(params) {
156
179
  var _this2 = this;
180
+ this.clearPreloadIframe();
157
181
  return this.parameterInitAndCheck({
158
182
  params: params,
159
183
  renderDisplayType: renderDisplayTypeEnum.popup
@@ -168,9 +192,37 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
168
192
  _this2._eventCenter.emit(EVENT.error.name, error);
169
193
  return Promise.reject(error);
170
194
  }).then(function (appendParams) {
195
+ var iframeNodesParams = appendParams.iframeNodesParams;
196
+ _this2.savePreviousChannel(iframeNodesParams);
171
197
  return _this2.pluginAppendIframe(appendParams);
172
198
  });
173
199
  }
200
+ }, {
201
+ key: "preloadComponent",
202
+ value: function preloadComponent(channelType, productSceneVersion) {
203
+ var _this3 = this;
204
+ this.channelType = channelType;
205
+ this.productSceneVersion = productSceneVersion;
206
+ var MAX_CLEAR_TIME = 10000;
207
+ if (Array.isArray(channelType)) {
208
+ for (var i = 0; i < channelType.length; i++) {
209
+ this._componentApp.appendPreloadIframeNodes(channelType[i], productSceneVersion);
210
+ }
211
+ }
212
+ setTimeout(function () {
213
+ _this3.clearPreloadIframe();
214
+ }, MAX_CLEAR_TIME);
215
+ }
216
+ }, {
217
+ key: "clearPreloadIframe",
218
+ value: function clearPreloadIframe() {
219
+ if (Array.isArray(this.channelType)) {
220
+ for (var i = 0; i < this.channelType.length; i++) {
221
+ var iframe = document.getElementById("ams-checkout-component-".concat(this.channelType[i], "-").concat(this.productSceneVersion));
222
+ iframe && document.body.removeChild(iframe);
223
+ }
224
+ }
225
+ }
174
226
  /**
175
227
  * @description Create and render components in the specified element area
176
228
  * @param params - The data source created by the component, necessary sessionData, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
@@ -179,7 +231,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
179
231
  }, {
180
232
  key: "mountComponent",
181
233
  value: function mountComponent(params, selector) {
182
- var _this3 = this;
234
+ var _this4 = this;
183
235
  return this.parameterInitAndCheck({
184
236
  params: params,
185
237
  renderDisplayType: renderDisplayTypeEnum.inline,
@@ -187,15 +239,17 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
187
239
  }).then(function (_params) {
188
240
  return handleParams(_params);
189
241
  }).catch(function (error) {
190
- _this3.logger.logError({
242
+ _this4.logger.logError({
191
243
  title: 'sdk_error_parameter'
192
244
  }, {
193
245
  params: JSON.stringify(params)
194
246
  }).send();
195
- _this3._eventCenter.emit(EVENT.error.name, error);
247
+ _this4._eventCenter.emit(EVENT.error.name, error);
196
248
  return Promise.reject(error);
197
249
  }).then(function (appendParams) {
198
- return _this3.pluginAppendIframe(appendParams);
250
+ var iframeNodesParams = appendParams.iframeNodesParams;
251
+ _this4.savePreviousChannel(iframeNodesParams);
252
+ return _this4.pluginAppendIframe(appendParams);
199
253
  });
200
254
  }
201
255
  /**
@@ -206,22 +260,22 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
206
260
  }, {
207
261
  key: "submit",
208
262
  value: function submit(data) {
209
- var _this4 = this;
263
+ var _this5 = this;
210
264
  return new Promise(function (resolve, reject) {
211
265
  try {
212
266
  var eventCallbackId = uuid();
213
267
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
- _this4._eventCenter.once(eventCallbackId, function (_data) {
268
+ _this5._eventCenter.once(eventCallbackId, function (_data) {
215
269
  resolve(_data);
216
270
  });
217
- _this4._componentApp.dispatchToApp({
271
+ _this5._componentApp.dispatchToApp({
218
272
  context: {
219
273
  event: 'submitPay',
220
274
  eventCallbackId: eventCallbackId,
221
275
  data: data
222
276
  }
223
277
  });
224
- _this4.logger.logInfo({
278
+ _this5.logger.logInfo({
225
279
  title: 'sdk_event_apiSubmit'
226
280
  });
227
281
  } catch (error) {
package/esm/index.d.ts CHANGED
@@ -1,8 +1,16 @@
1
- import { AMSComponent } from './core/component/index';
2
- import { IoptionsParams } from './types';
1
+ /**
2
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
+ * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
+ */
3
8
  import ApplePayComponent from './core/applepay';
9
+ import { AMSComponent } from './core/component/index';
10
+ import { IoptionsParams, componentSignEnum } from './types';
4
11
  export * from './types';
5
12
  export declare class AMSCheckout extends AMSComponent {
13
+ constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
6
14
  }
7
15
  export declare class AMSApplePay extends ApplePayComponent {
8
16
  }
package/esm/index.js CHANGED
@@ -18,16 +18,21 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
18
18
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
19
19
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
20
20
  */
21
- import { productSceneEnum } from "./types/index";
22
- import { AMSComponent } from "./core/component/index";
23
21
  import ApplePayComponent from "./core/applepay";
22
+ import { AMSComponent } from "./core/component/index";
23
+ import { componentSignEnum } from "./types";
24
+ import { productSceneEnum } from "./types/index";
24
25
  export * from "./types";
25
26
  export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
26
27
  _inherits(AMSCheckout, _AMSComponent);
27
28
  var _super = _createSuper(AMSCheckout);
28
- function AMSCheckout() {
29
+ function AMSCheckout(_options, channelType) {
30
+ var _this;
31
+ var productSceneVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '1.0';
29
32
  _classCallCheck(this, AMSCheckout);
30
- return _super.apply(this, arguments);
33
+ _this = _super.call(this, _options);
34
+ _this.preloadComponent(channelType, productSceneVersion);
35
+ return _this;
31
36
  }
32
37
  return _createClass(AMSCheckout);
33
38
  }(AMSComponent);
@@ -48,7 +53,7 @@ export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
48
53
  var _options = Object.assign({}, options, {
49
54
  product: productSceneEnum.AUTO_DEBIT
50
55
  });
51
- return _super3.call(this, _options);
56
+ return _super3.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
52
57
  }
53
58
  return _createClass(AMSAutoDebit);
54
59
  }(AMSCheckout);
@@ -60,7 +65,22 @@ export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
60
65
  var _options = Object.assign({}, options, {
61
66
  product: productSceneEnum.EASY_PAY
62
67
  });
63
- return _super4.call(this, _options);
68
+ var currentProductSceneVersion = '1.0';
69
+ try {
70
+ var previousChannelStr = localStorage.getItem('previousChannel');
71
+ var previousChannel = JSON.parse(previousChannelStr) || {};
72
+ var _ref = previousChannel || {},
73
+ _ref$channelType = _ref.channelType,
74
+ channelType = _ref$channelType === void 0 ? '' : _ref$channelType,
75
+ _ref$productSceneVers = _ref.productSceneVersion,
76
+ productSceneVersion = _ref$productSceneVers === void 0 ? '1.0' : _ref$productSceneVers;
77
+ if (channelType === componentSignEnum.EASY_PAY_WALLET) {
78
+ currentProductSceneVersion = productSceneVersion;
79
+ }
80
+ } catch (error) {
81
+ console.log(error);
82
+ }
83
+ return _super4.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
64
84
  }
65
85
  return _createClass(AMSEasyPay);
66
86
  }(AMSCheckout);
@@ -72,7 +92,22 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
72
92
  var _options = Object.assign({}, options, {
73
93
  product: productSceneEnum.CASHIER_PAYMENT
74
94
  });
75
- return _super5.call(this, _options);
95
+ var currentChannelType;
96
+ try {
97
+ var previousChannelStr = localStorage.getItem('previousChannel');
98
+ var previousChannel = JSON.parse(previousChannelStr) || {};
99
+ var _ref2 = previousChannel || {},
100
+ _ref2$channelType = _ref2.channelType,
101
+ channelType = _ref2$channelType === void 0 ? '' : _ref2$channelType;
102
+ if ([componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.CASHIER_PAYMENT_APM, componentSignEnum.CASHIER_PAYMENT_BANK].includes(channelType)) {
103
+ currentChannelType = [channelType];
104
+ } else {
105
+ currentChannelType = [componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.CASHIER_PAYMENT_APM];
106
+ }
107
+ } catch (error) {
108
+ console.log(error);
109
+ }
110
+ return _super5.call(this, _options, currentChannelType);
76
111
  }
77
112
  return _createClass(AMSCashierPayment);
78
113
  }(AMSCheckout);
@@ -84,7 +119,7 @@ export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
84
119
  var _options = Object.assign({}, options, {
85
120
  product: productSceneEnum.VAULTING
86
121
  });
87
- return _super6.call(this, _options);
122
+ return _super6.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
88
123
  }
89
124
  return _createClass(AMSVaulting);
90
125
  }(AMSCheckout);
@@ -17,6 +17,8 @@ export declare const getIframeUrl: (iframeParams: {
17
17
  locale: string;
18
18
  instanceId: string;
19
19
  renderDisplayType: renderDisplayTypeEnum;
20
+ isPreload?: string;
21
+ hostSign?: string;
20
22
  }) => {
21
23
  path: string;
22
24
  locationSearch: string;
@@ -25,3 +27,4 @@ export declare const getIframeUrl: (iframeParams: {
25
27
  * @description Create iframe
26
28
  */
27
29
  export declare const createIframe: (mode: string, platform: 'mobile' | 'desktop') => HTMLIFrameElement;
30
+ export declare const createPreloadIframe: (channelType: any, version: any) => HTMLIFrameElement;
@@ -69,7 +69,11 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
69
69
  extendInfo = iframeParams.extendInfo,
70
70
  locale = iframeParams.locale,
71
71
  instanceId = iframeParams.instanceId,
72
- renderDisplayType = iframeParams.renderDisplayType;
72
+ renderDisplayType = iframeParams.renderDisplayType,
73
+ _iframeParams$isPrelo = iframeParams.isPreload,
74
+ isPreload = _iframeParams$isPrelo === void 0 ? '' : _iframeParams$isPrelo,
75
+ _iframeParams$hostSig = iframeParams.hostSign,
76
+ hostSign = _iframeParams$hostSig === void 0 ? '' : _iframeParams$hostSig;
73
77
  var path = getAppPath(environment, appVersion, componentSign, productSceneVersion, extendInfo || '');
74
78
  var initialScale = 1;
75
79
  var scale = getViewPort('initial-scale') || initialScale;
@@ -90,7 +94,9 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
90
94
  analyticsEnabled: (analytics === null || analytics === void 0 ? void 0 : analytics.enabled) === false ? 'false' : 'true',
91
95
  sdkVersion: sdkVersion,
92
96
  refUrl: window.location.href,
93
- _componentStartTime: "".concat(Date.now())
97
+ _componentStartTime: "".concat(Date.now()),
98
+ isPreload: isPreload || '',
99
+ hostSign: hostSign || ''
94
100
  });
95
101
  if (LOCAL_MOCK) urlParams.LOCAL_MOCK = LOCAL_MOCK;
96
102
  if (requestHost) urlParams.requestHost = requestHost;
@@ -98,6 +104,7 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
98
104
  if (environment === 'light_sandbox' || _light_sandbox === 'true') urlParams.sandbox = 'true';
99
105
  if (environment === 'sandbox' || _sandbox === 'true') urlParams.shadow = 'true';
100
106
  if (_displayType) urlParams.displayType = _displayType;
107
+ if (isPreload) urlParams.isPreload = isPreload;
101
108
  var locationSearch = serialize(urlParams);
102
109
  return {
103
110
  path: path,
@@ -127,4 +134,18 @@ export var createIframe = function createIframe(mode, platform) {
127
134
  iframe.style.opacity = none;
128
135
  iframe.style.overflow = 'hidden';
129
136
  return iframe;
137
+ };
138
+ export var createPreloadIframe = function createPreloadIframe(channelType, version) {
139
+ var id = "ams-checkout-component-".concat(channelType, "-").concat(version);
140
+ var iframe = document.createElement('iframe');
141
+ var iframeId = id;
142
+ var none = '1px';
143
+ var width = '1px';
144
+ iframe.id = iframeId;
145
+ iframe.style.height = none;
146
+ iframe.style.width = width;
147
+ iframe.style.border = none;
148
+ iframe.style.opacity = '0';
149
+ iframe.style.overflow = 'hidden';
150
+ return iframe;
130
151
  };
@@ -13,6 +13,7 @@ export default class ComponentApp {
13
13
  private popupApp?;
14
14
  private appDomain;
15
15
  private createIframeNode;
16
+ private createPreloadIframeNode;
16
17
  private _selector;
17
18
  private _appVersion;
18
19
  private _isRetention;
@@ -40,6 +41,7 @@ export default class ComponentApp {
40
41
  * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
41
42
  */
42
43
  setRender(renderFunc: IrenderFuncParams): void;
44
+ setPreloadRender(renderFunc: any): void;
43
45
  private initSecurity;
44
46
  private logDeviceId;
45
47
  private getDeviceIdAndLog;
@@ -47,6 +49,7 @@ export default class ComponentApp {
47
49
  * @description render iframe content
48
50
  */
49
51
  appendIframeNodes(componentSign: componentSignEnum, renderParams: IappendIframeNodesParams): Promise<void>;
52
+ appendPreloadIframeNodes(componentSign: any, productSceneVersion: any): void;
50
53
  private setParameterDefaultValues;
51
54
  private renderInlineLoading;
52
55
  private renderPopupLoading;
@@ -57,6 +60,7 @@ export default class ComponentApp {
57
60
  private createActionQueryPromise;
58
61
  private createSubmitPromise;
59
62
  private cleanElement;
63
+ private createPreloadApp;
60
64
  /**
61
65
  * @description Create app
62
66
  */
@@ -22,7 +22,7 @@ import { queryPaymentInfo, submitPayInfo } from "../../service";
22
22
  import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, RedirectType, renderDisplayTypeEnum, targetEnum } from "../../types";
23
23
  import { getType, isJsonString, isPC } from "../../util";
24
24
  import { isLocalMock } from "../../util/mock";
25
- import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
25
+ import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
26
26
  import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
27
27
  import { addPopupLoading, createBaseElement, createMockup, createRetentionPopup, handleDeclareInfo as _handleDeclareInfo, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup } from "./component.popup.style";
28
28
  import { createModal, destroyModal, insertStyleSheet } from "./popupWindow.style";
@@ -40,6 +40,7 @@ var ComponentApp = /*#__PURE__*/function () {
40
40
  _defineProperty(this, "popupApp", void 0);
41
41
  _defineProperty(this, "appDomain", void 0);
42
42
  _defineProperty(this, "createIframeNode", void 0);
43
+ _defineProperty(this, "createPreloadIframeNode", void 0);
43
44
  _defineProperty(this, "_selector", void 0);
44
45
  _defineProperty(this, "_appVersion", void 0);
45
46
  _defineProperty(this, "_isRetention", void 0);
@@ -53,12 +54,15 @@ var ComponentApp = /*#__PURE__*/function () {
53
54
  _defineProperty(this, "_merchantAppointParam", void 0);
54
55
  _defineProperty(this, "_webAppHeartBeatTimeoutId", void 0);
55
56
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
56
- this._appVersion = '1.9.0';
57
+ this._appVersion = '1.10.1';
57
58
  this._isInitComponent = false;
58
59
  this._selector = "#".concat(COMPONENT_SECTION_ID);
59
60
  this.createIframeNode = function () {
60
61
  return Promise.resolve();
61
62
  };
63
+ this.createPreloadIframeNode = function () {
64
+ return Promise.resolve();
65
+ };
62
66
  this.platform = isPC() ? platformEnum.desktop : platformEnum.mobile;
63
67
  this._isRetention = true;
64
68
  this._appLocationSearch = '';
@@ -119,6 +123,11 @@ var ComponentApp = /*#__PURE__*/function () {
119
123
  value: function setRender(renderFunc) {
120
124
  this.createIframeNode = renderFunc;
121
125
  }
126
+ }, {
127
+ key: "setPreloadRender",
128
+ value: function setPreloadRender(renderFunc) {
129
+ this.createPreloadIframeNode = renderFunc;
130
+ }
122
131
  }, {
123
132
  key: "initSecurity",
124
133
  value: function initSecurity() {
@@ -280,6 +289,12 @@ var ComponentApp = /*#__PURE__*/function () {
280
289
  return Promise.reject(error);
281
290
  });
282
291
  }
292
+ }, {
293
+ key: "appendPreloadIframeNodes",
294
+ value: function appendPreloadIframeNodes(componentSign, productSceneVersion) {
295
+ var virtualPreloadIframe = this.createPreloadApp(componentSign, productSceneVersion);
296
+ this.createPreloadIframeNode(virtualPreloadIframe);
297
+ }
283
298
  }, {
284
299
  key: "setParameterDefaultValues",
285
300
  value: function setParameterDefaultValues(componentSign, renderParams) {
@@ -342,8 +357,8 @@ var ComponentApp = /*#__PURE__*/function () {
342
357
  // eslint-disable-next-line no-async-promise-executor
343
358
  this._actionQueryPromise = new Promise( /*#__PURE__*/function () {
344
359
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
345
- var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4;
346
- var envInfo, params, _this5$_renderParams5, _ref3, _ref3$productSceneVer, productSceneVersion, _ref3$productScene, productScene, _ref4, _ref4$action, _ref4$action2, _ref4$action2$autoDeb, autoDebitWithToken, _this5$_renderParams6, _action$web, _action$wap, action, signType;
360
+ var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4, _this5$_renderParams5, _this5$_renderParams6;
361
+ var envInfo, params, _this5$_renderParams$, extendInfo, enableVaultingApiOptimize, extendInfoData, _this5$_renderParams$2, _this5$_renderParams$3, paymentSessionFactor, _this5$_renderParams7, _ref3, _ref3$productSceneVer, productSceneVersion, _ref3$productScene, productScene, _ref4, _ref4$action, _ref4$action2, _ref4$action2$autoDeb, autoDebitWithToken, _this5$_renderParams8, _action$web, _action$wap, action, signType;
347
362
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
348
363
  while (1) switch (_context2.prev = _context2.next) {
349
364
  case 0:
@@ -359,78 +374,98 @@ var ComponentApp = /*#__PURE__*/function () {
359
374
  /**
360
375
  * @description Simulated or unnecessary scenarios
361
376
  */
362
- if (!(isLocalMock() || (_this5$_renderParams4 = _this5._renderParams) !== null && _this5$_renderParams4 !== void 0 && (_this5$_renderParams4 = _this5$_renderParams4.paymentSessionMetaData) !== null && _this5$_renderParams4 !== void 0 && (_this5$_renderParams4 = _this5$_renderParams4.action) !== null && _this5$_renderParams4 !== void 0 && _this5$_renderParams4.skipSdkQuery)) {
363
- _context2.next = 4;
377
+ _this5$_renderParams$ = (_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData, extendInfo = _this5$_renderParams$.extendInfo;
378
+ enableVaultingApiOptimize = false;
379
+ try {
380
+ extendInfoData = JSON.parse(extendInfo);
381
+ enableVaultingApiOptimize = extendInfoData.enableVaultingApiOptimize || false;
382
+ } catch (error) {
383
+ console.log(error);
384
+ }
385
+ if (!isLocalMock()) {
386
+ _context2.next = 7;
364
387
  break;
365
388
  }
366
389
  return _context2.abrupt("return", resolve({
367
390
  message: 'sdk no need to make query request',
368
391
  success: true
369
392
  }));
370
- case 4:
371
- if (!(componentSignEnum.CASHIER_PAYMENT_CARD === _this5._componentSign || componentSignEnum.VAULTING_CARD === _this5._componentSign)) {
393
+ case 7:
394
+ // 绑卡跳过actionQuery接口
395
+ // paymentSessionFactor 该字段没值则走不跳过接口逻辑
396
+ _this5$_renderParams$2 = (_this5$_renderParams5 = _this5._renderParams) === null || _this5$_renderParams5 === void 0 ? void 0 : _this5$_renderParams5.paymentSessionMetaData, _this5$_renderParams$3 = _this5$_renderParams$2.paymentSessionFactor, paymentSessionFactor = _this5$_renderParams$3 === void 0 ? null : _this5$_renderParams$3;
397
+ if (!(componentSignEnum.VAULTING_CARD === _this5._componentSign && (_this5$_renderParams6 = _this5._renderParams) !== null && _this5$_renderParams6 !== void 0 && (_this5$_renderParams6 = _this5$_renderParams6.paymentSessionMetaData) !== null && _this5$_renderParams6 !== void 0 && (_this5$_renderParams6 = _this5$_renderParams6.action) !== null && _this5$_renderParams6 !== void 0 && _this5$_renderParams6.skipSdkQuery && enableVaultingApiOptimize && paymentSessionFactor)) {
372
398
  _context2.next = 10;
373
399
  break;
374
400
  }
401
+ return _context2.abrupt("return", resolve({
402
+ message: 'sdk no need to make query request',
403
+ success: true
404
+ }));
405
+ case 10:
406
+ if (!(componentSignEnum.CASHIER_PAYMENT_CARD === _this5._componentSign || componentSignEnum.VAULTING_CARD === _this5._componentSign)) {
407
+ _context2.next = 16;
408
+ break;
409
+ }
375
410
  params.paymentMethodType = 'CARD';
376
- _context2.next = 8;
411
+ _context2.next = 14;
377
412
  return _this5.getDeviceIdAndLog();
378
- case 8:
413
+ case 14:
379
414
  envInfo.deviceId = _context2.sent;
380
415
  if (window.navigator.userAgent.indexOf('miniProgram') > -1) {
381
416
  envInfo.extendInfo = {
382
417
  WAP_SUB_TYPE: 'WECHAT_MINI_PROGRAM'
383
418
  };
384
419
  }
385
- case 10:
420
+ case 16:
386
421
  if (!(componentSignEnum.EASY_PAY_WALLET === _this5._componentSign)) {
387
- _context2.next = 18;
422
+ _context2.next = 24;
388
423
  break;
389
424
  }
390
425
  _ref3 = params.paymentSessionConfig || {}, _ref3$productSceneVer = _ref3.productSceneVersion, productSceneVersion = _ref3$productSceneVer === void 0 ? '' : _ref3$productSceneVer, _ref3$productScene = _ref3.productScene, productScene = _ref3$productScene === void 0 ? '' : _ref3$productScene;
391
- _ref4 = ((_this5$_renderParams5 = _this5._renderParams) === null || _this5$_renderParams5 === void 0 ? void 0 : _this5$_renderParams5.paymentSessionMetaData) || {}, _ref4$action = _ref4.action, _ref4$action2 = _ref4$action === void 0 ? {} : _ref4$action, _ref4$action2$autoDeb = _ref4$action2.autoDebitWithToken, autoDebitWithToken = _ref4$action2$autoDeb === void 0 ? false : _ref4$action2$autoDeb;
426
+ _ref4 = ((_this5$_renderParams7 = _this5._renderParams) === null || _this5$_renderParams7 === void 0 ? void 0 : _this5$_renderParams7.paymentSessionMetaData) || {}, _ref4$action = _ref4.action, _ref4$action2 = _ref4$action === void 0 ? {} : _ref4$action, _ref4$action2$autoDeb = _ref4$action2.autoDebitWithToken, autoDebitWithToken = _ref4$action2$autoDeb === void 0 ? false : _ref4$action2$autoDeb;
392
427
  if (!(productScene === productSceneEnum.EASY_PAY && productSceneVersion === '2.0' && !autoDebitWithToken)) {
393
- _context2.next = 15;
428
+ _context2.next = 21;
394
429
  break;
395
430
  }
396
431
  return _context2.abrupt("return", resolve({
397
432
  message: 'sdk no need to make query request',
398
433
  success: true
399
434
  }));
400
- case 15:
401
- _context2.next = 17;
435
+ case 21:
436
+ _context2.next = 23;
402
437
  return _this5.getDeviceIdAndLog();
403
- case 17:
438
+ case 23:
404
439
  envInfo.deviceId = _context2.sent;
405
- case 18:
440
+ case 24:
406
441
  if (!(componentSignEnum.AUTO_DEBIT_WALLET === _this5._componentSign)) {
407
- _context2.next = 28;
442
+ _context2.next = 34;
408
443
  break;
409
444
  }
410
- action = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 || (_this5$_renderParams6 = _this5$_renderParams6.paymentSessionMetaData) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.action) || {};
445
+ action = ((_this5$_renderParams8 = _this5._renderParams) === null || _this5$_renderParams8 === void 0 || (_this5$_renderParams8 = _this5$_renderParams8.paymentSessionMetaData) === null || _this5$_renderParams8 === void 0 ? void 0 : _this5$_renderParams8.action) || {};
411
446
  signType = isPC() ? action === null || action === void 0 || (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 || (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType;
412
447
  if (!(signType === 'SMS')) {
413
- _context2.next = 23;
448
+ _context2.next = 29;
414
449
  break;
415
450
  }
416
451
  return _context2.abrupt("return", resolve({
417
452
  message: 'sdk no need to make query request',
418
453
  success: true
419
454
  }));
420
- case 23:
455
+ case 29:
421
456
  if (!(!signType || signType !== 'REDIRECT')) {
422
- _context2.next = 25;
457
+ _context2.next = 31;
423
458
  break;
424
459
  }
425
460
  return _context2.abrupt("return", resolve({
426
461
  success: false
427
462
  }));
428
- case 25:
429
- _context2.next = 27;
463
+ case 31:
464
+ _context2.next = 33;
430
465
  return _this5.getDeviceIdAndLog();
431
- case 27:
466
+ case 33:
432
467
  envInfo.deviceId = _context2.sent;
433
- case 28:
468
+ case 34:
434
469
  _this5.AMSSDK.logger.logInfo({
435
470
  title: 'sdk_event_sdkQuery'
436
471
  }, {
@@ -444,11 +479,7 @@ var ComponentApp = /*#__PURE__*/function () {
444
479
  key: 'sdk_action_query_end',
445
480
  value: Date.now()
446
481
  });
447
- if (res !== null && res !== void 0 && res.success) {
448
- resolve(res);
449
- } else {
450
- resolve(res);
451
- }
482
+ resolve(res);
452
483
  }).catch(function (err) {
453
484
  if ([componentSignEnum.CASHIER_PAYMENT_CARD, componentSignEnum.VAULTING_CARD, componentSignEnum.CASHIER_PAYMENT_APM].includes(_this5._componentSign)) {
454
485
  return resolve({
@@ -466,7 +497,7 @@ var ComponentApp = /*#__PURE__*/function () {
466
497
  paymentSessionConfig: JSON.stringify(params.paymentSessionConfig)
467
498
  }).send();
468
499
  });
469
- case 30:
500
+ case 36:
470
501
  case "end":
471
502
  return _context2.stop();
472
503
  }
@@ -478,6 +509,8 @@ var ComponentApp = /*#__PURE__*/function () {
478
509
  }());
479
510
  return this._actionQueryPromise;
480
511
  }
512
+
513
+ // private create
481
514
  }, {
482
515
  key: "createSubmitPromise",
483
516
  value: function createSubmitPromise() {
@@ -593,7 +626,33 @@ var ComponentApp = /*#__PURE__*/function () {
593
626
  console.error(error);
594
627
  }
595
628
  }
596
-
629
+ // 预加载iframe创建
630
+ }, {
631
+ key: "createPreloadApp",
632
+ value: function createPreloadApp(componentSign) {
633
+ var productSceneVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.0';
634
+ var preloadIframe = createPreloadIframe(componentSign, productSceneVersion);
635
+ var _getIframeUrl = getIframeUrl({
636
+ renderDisplayType: renderDisplayTypeEnum.popup,
637
+ componentSign: componentSign,
638
+ analytics: {
639
+ enabled: false
640
+ },
641
+ productSceneVersion: productSceneVersion,
642
+ environment: this.AMSSDK.options.env.environment,
643
+ // TODO 确定一下这个参数是干啥的
644
+ appVersion: this._appVersion,
645
+ extendInfo: '',
646
+ locale: '',
647
+ instanceId: '',
648
+ isPreload: 'true'
649
+ }),
650
+ path = _getIframeUrl.path,
651
+ locationSearch = _getIframeUrl.locationSearch;
652
+ preloadIframe.src = "".concat(path, "?").concat(locationSearch);
653
+ console.log(preloadIframe.src, '--preloadIframe.src');
654
+ return preloadIframe;
655
+ }
597
656
  /**
598
657
  * @description Create app
599
658
  */
@@ -621,7 +680,8 @@ var ComponentApp = /*#__PURE__*/function () {
621
680
  extendInfo: extendInfo
622
681
  });
623
682
  this.app = createIframe(this.AMSSDK.options.mode, this.platform);
624
- var _getIframeUrl = getIframeUrl({
683
+ var hostSign = ((renderParams === null || renderParams === void 0 ? void 0 : renderParams.sessionData) || '').split('&&')[1] || '';
684
+ var _getIframeUrl2 = getIframeUrl({
625
685
  renderDisplayType: renderParams.renderDisplayType,
626
686
  componentSign: this._componentSign,
627
687
  analytics: this.AMSSDK.options.analytics,
@@ -630,10 +690,11 @@ var ComponentApp = /*#__PURE__*/function () {
630
690
  appVersion: this._appVersion,
631
691
  extendInfo: extendInfo,
632
692
  locale: this.AMSSDK.options.locale,
633
- instanceId: this.AMSSDK._instanceId
693
+ instanceId: this.AMSSDK._instanceId,
694
+ hostSign: hostSign
634
695
  }),
635
- path = _getIframeUrl.path,
636
- locationSearch = _getIframeUrl.locationSearch;
696
+ path = _getIframeUrl2.path,
697
+ locationSearch = _getIframeUrl2.locationSearch;
637
698
  this._appLocationSearch = locationSearch;
638
699
  this.app.src = "".concat(path, "?").concat(locationSearch);
639
700