@alipay/ams-checkout 0.0.1700804278-dev.1 → 0.0.1701393225-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.
@@ -17,33 +17,39 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
17
17
  */
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
19
  import { v4 as uuid } from 'uuid';
20
- import { LogConfig, Logger } from "../../util/logger";
20
+ import { sdkVersion } from "../../config/index";
21
21
  import { ERRORMESSAGE, EVENT } from "../../constant";
22
- import { environmentEnum, modeEnum, networkModeEnum, osTypeEnum, terminalTypeEnum } from "../../types/index";
23
- import { device, EventCenter, getType, queryParse } from "../../util/index";
22
+ import { antomConfig } from "../../service";
23
+ import { environmentEnum, modeEnum, networkModeEnum, osTypeEnum, productSceneEnum, terminalTypeEnum } from "../../types/index";
24
+ import { checkTimeElapsed, device, EventCenter, getOrSetStorageId, getType, queryParse, safeJson } from "../../util/index";
24
25
  import CallApp from "../../util/intl-callapp/es/main";
25
- import { initAPSecurity } from "../../util/security";
26
-
27
- // TODO Faster initialization of buried point tools
26
+ import { LogConfig, Logger } from "../../util/logger";
27
+ import { compareVersion } from "../../util/versionCompare";
28
+ import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum } from "../../util/security";
28
29
  var AMSSDK = /*#__PURE__*/function () {
29
30
  function AMSSDK(options) {
30
31
  _classCallCheck(this, AMSSDK);
31
32
  _defineProperty(this, "options", void 0);
32
- _defineProperty(this, "checkoutState", void 0);
33
- _defineProperty(this, "securityConfig", void 0);
33
+ _defineProperty(this, "logger", void 0);
34
34
  _defineProperty(this, "_eventCenter", void 0);
35
- _defineProperty(this, "plugins", void 0);
36
35
  _defineProperty(this, "_instanceId", void 0);
37
36
  _defineProperty(this, "_storageId", void 0);
38
- _defineProperty(this, "logger", void 0);
37
+ _defineProperty(this, "securitySdkMap", void 0);
38
+ _defineProperty(this, "plugins", void 0);
39
39
  this._instanceId = uuid();
40
- this._storageId = this.getStorageId(this._instanceId);
41
40
  this.options = {};
42
41
  this._eventCenter = new EventCenter();
43
42
  this._initEvent(options);
44
43
  this._setOptions(options);
45
44
  this.plugins = new Map();
46
- this.securityConfig = null;
45
+ this.securitySdkMap = new Map();
46
+ var storageIdKey = 'AMSSDK_STORAGE_ID';
47
+ var _storageId = getOrSetStorageId(storageIdKey);
48
+ if (!_storageId) {
49
+ getOrSetStorageId(storageIdKey, this._instanceId);
50
+ _storageId = this._instanceId;
51
+ }
52
+ this._storageId = _storageId;
47
53
 
48
54
  // TODO Consumption data analysis control parameters
49
55
  this.logger = new Logger(LogConfig, (options === null || options === void 0 ? void 0 : options.environment) !== environmentEnum.prod);
@@ -55,14 +61,44 @@ var AMSSDK = /*#__PURE__*/function () {
55
61
  title: 'NEW_AMSSDK_BY_MECHANT',
56
62
  msg: "".concat(options === null || options === void 0 ? void 0 : options.environment, "_").concat(options === null || options === void 0 ? void 0 : options.locale, "}")
57
63
  }).send();
58
- if (options !== null && options !== void 0 && options.securityConfig) {
59
- this.initSecurity(options === null || options === void 0 ? void 0 : options.securityConfig);
60
- }
64
+ this.preInitSecurity();
61
65
  }
62
- /**
63
- * @description Destroy and process some contents of the plug-in
64
- */
65
66
  _createClass(AMSSDK, [{
67
+ key: "preInitSecurity",
68
+ value: function preInitSecurity() {
69
+ var _this$options;
70
+ var antomSDKConfigKey = 'antomSDKConfigKey';
71
+ var config = safeJson(getOrSetStorageId(antomSDKConfigKey), {});
72
+ if (checkTimeElapsed()) {
73
+ antomConfig({
74
+ env: this.options.env.environment
75
+ }, this.logger).then(function (res) {
76
+ getOrSetStorageId(antomSDKConfigKey, JSON.stringify(res));
77
+ });
78
+ }
79
+ var product = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.product) || productSceneEnum.EASY_PAY;
80
+ var enable = true;
81
+ try {
82
+ var matchingConfig = config['pl_sec'].find(function (item) {
83
+ var _item$v, _item$v2, _item$platform;
84
+ var minVersion = item === null || item === void 0 || (_item$v = item.v) === null || _item$v === void 0 ? void 0 : _item$v.split('|')[0];
85
+ var maxVersion = (item === null || item === void 0 || (_item$v2 = item.v) === null || _item$v2 === void 0 ? void 0 : _item$v2.split('|')[1]) || '999.9.9';
86
+ var matchVersion = compareVersion(sdkVersion, minVersion) >= 0 && compareVersion(maxVersion, sdkVersion) >= 0;
87
+ return ((item === null || item === void 0 || (_item$platform = item.platform) === null || _item$platform === void 0 ? void 0 : _item$platform.includes('Web')) || (item === null || item === void 0 ? void 0 : item.platform) === '') && (item === null || item === void 0 ? void 0 : item.product) === product && (!(item !== null && item !== void 0 && item.v) || matchVersion);
88
+ });
89
+ enable = (matchingConfig === null || matchingConfig === void 0 ? void 0 : matchingConfig.enable) === false ? false : true;
90
+ } catch (error) {
91
+ /* empty */
92
+ }
93
+ if (!enable) return;
94
+ this.initSecurity({
95
+ product: product
96
+ });
97
+ }
98
+ /**
99
+ * @description Destroy and process some contents of the plug-in
100
+ */
101
+ }, {
66
102
  key: "unmount",
67
103
  value: function unmount() {
68
104
  this.logger.logInfo({
@@ -86,56 +122,98 @@ var AMSSDK = /*#__PURE__*/function () {
86
122
  _iterator.f();
87
123
  }
88
124
  }
89
-
90
125
  /**
91
- * @description set STORAGE_ID for a user session
126
+ * @description init security SDK
127
+ * @param product Product Scenarios
128
+ * @param scene Scenario of the product (compatible with old version parameters, about to be deleted)
92
129
  */
93
130
  }, {
94
- key: "getStorageId",
95
- value: function getStorageId(instanceId) {
96
- var storageKey = 'AMSSDK_STORAGE_ID';
97
- try {
98
- if (window.localStorage) {
99
- var storageId = window.localStorage.getItem(storageKey);
100
- if (storageId) {
101
- return storageId;
102
- } else {
103
- window.localStorage.setItem(storageKey, instanceId);
104
- }
105
- }
106
- } catch (error) {/* empty */}
107
- return instanceId;
131
+ key: "initSecurity",
132
+ value: function initSecurity(_ref) {
133
+ var _this = this;
134
+ var _ref$product = _ref.product,
135
+ product = _ref$product === void 0 ? productSceneEnum.EASY_PAY : _ref$product,
136
+ _ref$scene = _ref.scene,
137
+ scene = _ref$scene === void 0 ? productSceneEnum.EASY_PAY : _ref$scene;
138
+ this.logger.logInfo({
139
+ title: 'sdk_event_securitySdkPreInit'
140
+ }, {
141
+ product: product
142
+ }).send();
143
+ var sdk = this._getSecuritySDKByProductScene({
144
+ product: product || scene
145
+ });
146
+ if (sdk) return;
147
+ this._newSecuritySDKByScene({
148
+ product: product || scene,
149
+ region: SecurityRegionEnum.SG
150
+ }, function () {
151
+ _this.logger.logInfo({
152
+ title: 'sdk_event_securitySdkPreInitSuccess'
153
+ }, {
154
+ product: product
155
+ }).send();
156
+ }, function (msg) {
157
+ _this.logger.logError({
158
+ title: 'sdk_error_securitySdkInitFailed',
159
+ msg: msg
160
+ }, {
161
+ product: product,
162
+ sign: 'Active initialization'
163
+ }).send();
164
+ });
108
165
  }
109
-
110
166
  /**
111
- * @description init initSecurity SDK
167
+ * @description Obtain security SDK through scenario identification
112
168
  */
113
169
  }, {
114
- key: "initSecurity",
115
- value: function initSecurity(securityConfig) {
116
- var _this = this;
170
+ key: "_getSecuritySDKByProductScene",
171
+ value: function _getSecuritySDKByProductScene(securityConfig) {
172
+ var storage = this.getSecurityConfigStorage(securityConfig.product);
173
+ var scene = storage.scene || getSecurityScene(securityConfig.product);
174
+ var securitySdk = this.securitySdkMap.get(scene);
175
+ return securitySdk;
176
+ }
177
+ /**
178
+ * @description New security SDK through scenario identification
179
+ */
180
+ }, {
181
+ key: "_newSecuritySDKByScene",
182
+ value: function _newSecuritySDKByScene(securityConfig, successCallback, failCallback) {
183
+ var storage = this.getSecurityConfigStorage(securityConfig.product);
184
+ var scene = storage.scene || getSecurityScene(securityConfig.product);
185
+ var h5gateway = storage.h5gateway || getSecurityHost(securityConfig.region);
117
186
  try {
118
- this.securityConfig = securityConfig;
119
- initAPSecurity(securityConfig, function () {
120
- _this.logger.logInfo({
121
- title: 'sdk_event_securitySdkPreInitSuccess'
122
- }).send();
123
- }, function (msg) {
124
- _this.logger.logError({
125
- title: 'sdk_error_securitySdkInitFailed',
126
- msg: msg
127
- }).send();
187
+ var securitySdk = new Security({
188
+ scene: scene,
189
+ h5gateway: h5gateway
128
190
  });
129
- this.logger.logInfo({
130
- title: 'sdk_event_securitySdkPreInit'
131
- }).send();
132
- } catch (e) {
133
- this.logger.logError({
134
- title: 'sdk_error_securitySdkInitFailed'
135
- }).send();
191
+ this.securitySdkMap.set(scene, securitySdk);
192
+ securitySdk.initSecurity(successCallback, failCallback);
193
+ return securitySdk;
194
+ } catch (error) {
195
+ failCallback && failCallback(JSON.stringify(error));
136
196
  }
137
197
  }
138
-
198
+ /**
199
+ * @description Obtain risk control configuration in local storage
200
+ */
201
+ }, {
202
+ key: "getSecurityConfigStorage",
203
+ value: function getSecurityConfigStorage(product) {
204
+ var scene = '';
205
+ var h5gateway = '';
206
+ var securityConfigStorage = getOrSetStorageId(getSecurityConfigStorageKey(product));
207
+ if (securityConfigStorage) {
208
+ var config = safeJson(securityConfigStorage, {});
209
+ scene = config === null || config === void 0 ? void 0 : config.appName;
210
+ h5gateway = config === null || config === void 0 ? void 0 : config.h5gateway;
211
+ }
212
+ return {
213
+ scene: scene,
214
+ h5gateway: h5gateway
215
+ };
216
+ }
139
217
  /**
140
218
  * @description Set the sdk basic configuration
141
219
  */
@@ -145,6 +223,7 @@ var AMSSDK = /*#__PURE__*/function () {
145
223
  this._setMode(options);
146
224
  this._setEnv(options);
147
225
  this.options.locale = (options === null || options === void 0 ? void 0 : options.locale) || '';
226
+ this.options.product = options === null || options === void 0 ? void 0 : options.product;
148
227
  }
149
228
  /**
150
229
  * @description Set environment variables
package/esm/index.d.ts CHANGED
@@ -1,16 +1,21 @@
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
- */
8
1
  import { AMSComponent } from './core/component/index';
9
2
  import { IoptionsParams } from './types';
3
+ import ApplePayComponent from './core/applepay';
10
4
  export * from './types';
11
5
  export declare class AMSCheckout extends AMSComponent {
12
6
  }
7
+ export declare class AMSApplePay extends ApplePayComponent {
8
+ }
13
9
  export declare class AMSAutoDebit extends AMSCheckout {
14
10
  constructor(options: IoptionsParams);
15
11
  }
12
+ export declare class AMSEasyPay extends AMSCheckout {
13
+ constructor(options: IoptionsParams);
14
+ }
15
+ export declare class AMSCashierPayment extends AMSCheckout {
16
+ constructor(options: IoptionsParams);
17
+ }
18
+ export declare class AMSVaulting extends AMSCheckout {
19
+ constructor(options: IoptionsParams);
20
+ }
16
21
  export default AMSCheckout;
package/esm/index.js CHANGED
@@ -18,7 +18,9 @@ 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";
21
22
  import { AMSComponent } from "./core/component/index";
23
+ import ApplePayComponent from "./core/applepay";
22
24
  export * from "./types";
23
25
  export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
24
26
  _inherits(AMSCheckout, _AMSComponent);
@@ -29,13 +31,61 @@ export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
29
31
  }
30
32
  return _createClass(AMSCheckout);
31
33
  }(AMSComponent);
34
+ export var AMSApplePay = /*#__PURE__*/function (_ApplePayComponent) {
35
+ _inherits(AMSApplePay, _ApplePayComponent);
36
+ var _super2 = _createSuper(AMSApplePay);
37
+ function AMSApplePay() {
38
+ _classCallCheck(this, AMSApplePay);
39
+ return _super2.apply(this, arguments);
40
+ }
41
+ return _createClass(AMSApplePay);
42
+ }(ApplePayComponent);
32
43
  export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
33
44
  _inherits(AMSAutoDebit, _AMSCheckout);
34
- var _super2 = _createSuper(AMSAutoDebit);
45
+ var _super3 = _createSuper(AMSAutoDebit);
35
46
  function AMSAutoDebit(options) {
36
47
  _classCallCheck(this, AMSAutoDebit);
37
- return _super2.call(this, options);
48
+ var _options = Object.assign({}, options, {
49
+ product: productSceneEnum.AUTO_DEBIT
50
+ });
51
+ return _super3.call(this, _options);
38
52
  }
39
53
  return _createClass(AMSAutoDebit);
40
54
  }(AMSCheckout);
55
+ export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
56
+ _inherits(AMSEasyPay, _AMSCheckout2);
57
+ var _super4 = _createSuper(AMSEasyPay);
58
+ function AMSEasyPay(options) {
59
+ _classCallCheck(this, AMSEasyPay);
60
+ var _options = Object.assign({}, options, {
61
+ product: productSceneEnum.EASY_PAY
62
+ });
63
+ return _super4.call(this, _options);
64
+ }
65
+ return _createClass(AMSEasyPay);
66
+ }(AMSCheckout);
67
+ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
68
+ _inherits(AMSCashierPayment, _AMSCheckout3);
69
+ var _super5 = _createSuper(AMSCashierPayment);
70
+ function AMSCashierPayment(options) {
71
+ _classCallCheck(this, AMSCashierPayment);
72
+ var _options = Object.assign({}, options, {
73
+ product: productSceneEnum.CASHIER_PAYMENT
74
+ });
75
+ return _super5.call(this, _options);
76
+ }
77
+ return _createClass(AMSCashierPayment);
78
+ }(AMSCheckout);
79
+ export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
80
+ _inherits(AMSVaulting, _AMSCheckout4);
81
+ var _super6 = _createSuper(AMSVaulting);
82
+ function AMSVaulting(options) {
83
+ _classCallCheck(this, AMSVaulting);
84
+ var _options = Object.assign({}, options, {
85
+ product: productSceneEnum.VAULTING
86
+ });
87
+ return _super6.call(this, _options);
88
+ }
89
+ return _createClass(AMSVaulting);
90
+ }(AMSCheckout);
41
91
  export default AMSCheckout;
@@ -90,7 +90,8 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
90
90
  instanceId: instanceId,
91
91
  analyticsEnabled: (analytics === null || analytics === void 0 ? void 0 : analytics.enabled) === false ? 'false' : 'true',
92
92
  sdkVersion: sdkVersion,
93
- refUrl: window.location.href
93
+ refUrl: window.location.href,
94
+ _componentStartTime: "".concat(Date.now())
94
95
  });
95
96
  if (LOCAL_MOCK) urlParams.LOCAL_MOCK = LOCAL_MOCK;
96
97
  if (requestHost) urlParams.requestHost = requestHost;
@@ -17,6 +17,7 @@ export default class ComponentApp {
17
17
  private _appVersion;
18
18
  private _isRetention;
19
19
  private _actionQueryPromise;
20
+ private _actionSubmitPromise;
20
21
  private _renderParams;
21
22
  private _componentSign;
22
23
  private _appLocationSearch;
@@ -36,7 +37,7 @@ export default class ComponentApp {
36
37
  * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
37
38
  */
38
39
  setRender(renderFunc: IrenderFuncParams): void;
39
- private initAPSecurity;
40
+ private initSecurity;
40
41
  private logDeviceId;
41
42
  private getDeviceIdAndLog;
42
43
  /**
@@ -50,6 +51,7 @@ export default class ComponentApp {
50
51
  * @description Interface request
51
52
  */
52
53
  private createActionQueryPromise;
54
+ private createSubmitPromise;
53
55
  private cleanElement;
54
56
  /**
55
57
  * @description Create app