@alipay/ams-checkout 0.0.1705989903-dev.0 → 0.0.1708315090-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.
@@ -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.logError({
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
  */