@alipay/ams-checkout 0.0.1699585541-dev.8 → 0.0.1699863258-dev.1

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.
@@ -1,2 +1,3 @@
1
1
  export declare const marmotMap: Record<string, string>;
2
+ export declare const marmotConfigMap: Record<string, string>;
2
3
  export declare const sdkVersion: string;
@@ -14,4 +14,12 @@ export var marmotMap = {
14
14
  light_sandbox: 'https://cdn.marmot-cloud.com/page/antom-web-checkout/src/component-app',
15
15
  prod: 'https://cdn.marmot-cloud.com/page/antom-web-checkout/src/component-app'
16
16
  };
17
+ export var marmotConfigMap = {
18
+ dev: 'https://config-dev.marmot-cloud.com/config/data/antom-sdk-config/en_US.json',
19
+ sit: 'https://config-test.marmot-cloud.com/config/data/antom-sdk-config/en_US.json',
20
+ pre: 'https://config-pre.marmot-cloud.com/config/data/antom-sdk-config/en_US.json',
21
+ sandbox: 'https://config.marmot-cloud.com/config/data/antom-sdk-config/en_US.json',
22
+ light_sandbox: 'https://config.marmot-cloud.com/config/data/antom-sdk-config/en_US.json',
23
+ prod: 'https://config.marmot-cloud.com/config/data/antom-sdk-config/en_US.json'
24
+ };
17
25
  export var sdkVersion = json.version;
@@ -13,12 +13,14 @@ export declare class AMSComponent extends CoreInstance {
13
13
  createComponent(params: IcreateComponent): Promise<void>;
14
14
  /**
15
15
  * @description Create and render components in the specified element area
16
- * @param params - The data source created by the component, necessary sessionData, necessary element selector IDs, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
16
+ * @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.
17
+ * @param selector - Necessary element selector ID
17
18
  */
18
19
  mountComponent(params: IcreateComponent, selector: Iselector): Promise<void>;
19
20
  /**
20
21
  * @description Execute payment submission process
21
22
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
23
+ * @param data - Transfer information in the submission interface according to your requirements (optional)
22
24
  */
23
25
  submit(data?: Isubmit): Promise<unknown>;
24
26
  }
@@ -29,8 +29,9 @@ import { v4 as uuid } from 'uuid';
29
29
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
30
30
  import ComponentApp from "../../plugin/component";
31
31
  import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
- import { isPC } from "../../util";
32
+ import { getOrSetStorageId, isPC } from "../../util";
33
33
  import { createIframeNode } from "../../util/createIframeNode";
34
+ import { getSecurityConfigStorageKey } from "../../util/security";
34
35
  import CoreInstance from "../instance/index";
35
36
  var getComponentSign = function getComponentSign(params) {
36
37
  var _params$paymentSessio = params.paymentSessionConfig,
@@ -84,6 +85,11 @@ var handleParams = function handleParams(params) {
84
85
  message: "Abnormal response data, interface failure, or unsupported payment method"
85
86
  });
86
87
  }
88
+ if (parseData && parseData !== null && parseData !== void 0 && parseData.securityConfig) {
89
+ var _parseData$paymentSes;
90
+ var product = parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionConfig) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.productScene;
91
+ getOrSetStorageId(getSecurityConfigStorageKey(product), JSON.stringify(parseData === null || parseData === void 0 ? void 0 : parseData.securityConfig));
92
+ }
87
93
  _params.sessionData = sessionData;
88
94
  _params.paymentSessionMetaData = parseData;
89
95
  return Promise.resolve({
@@ -140,7 +146,6 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
140
146
  return Promise.reject(error);
141
147
  }
142
148
  }
143
-
144
149
  /**
145
150
  * @description Create component application
146
151
  * @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.
@@ -163,7 +168,8 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
163
168
  }
164
169
  /**
165
170
  * @description Create and render components in the specified element area
166
- * @param params - The data source created by the component, necessary sessionData, necessary element selector IDs, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
171
+ * @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.
172
+ * @param selector - Necessary element selector ID
167
173
  */
168
174
  }, {
169
175
  key: "mountComponent",
@@ -185,6 +191,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
185
191
  /**
186
192
  * @description Execute payment submission process
187
193
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
194
+ * @param data - Transfer information in the submission interface according to your requirements (optional)
188
195
  */
189
196
  }, {
190
197
  key: "submit",
@@ -1,28 +1,41 @@
1
- import { Logger } from '../../util/logger';
2
- import type { AMSCheckoutOptions, IcheckoutState, IoptionsParams, IsecurityConfig } from '../../types/index';
1
+ import type { AMSCheckoutOptions, InitSecurityConfig, IoptionsParams } from '../../types/index';
3
2
  import { EventCenter } from '../../util/index';
3
+ import { Logger } from '../../util/logger';
4
+ import { Security } from '../../util/security';
4
5
  export default class AMSSDK {
5
6
  options: AMSCheckoutOptions;
6
- checkoutState: IcheckoutState;
7
- securityConfig: IsecurityConfig;
7
+ logger: Logger;
8
8
  _eventCenter: EventCenter;
9
- protected plugins: Map<string, any>;
10
9
  _instanceId: string;
11
10
  _storageId: string;
12
- logger: Logger;
11
+ protected securitySdkMap: Map<string, Security>;
12
+ protected plugins: Map<string, any>;
13
13
  constructor(options: IoptionsParams);
14
+ private preInitSecurity;
14
15
  /**
15
16
  * @description Destroy and process some contents of the plug-in
16
17
  */
17
18
  unmount(): void;
18
19
  /**
19
- * @description set STORAGE_ID for a user session
20
+ * @description init security SDK
21
+ * @param product Product Scenarios
22
+ * @param scene Scenario of the product (compatible with old version parameters, about to be deleted)
23
+ */
24
+ initSecurity({ product, scene, }: InitSecurityConfig & {
25
+ scene?: string;
26
+ }): void;
27
+ /**
28
+ * @description Obtain security SDK through scenario identification
29
+ */
30
+ _getSecuritySDKByProductScene(securityConfig: InitSecurityConfig): Security;
31
+ /**
32
+ * @description New security SDK through scenario identification
20
33
  */
21
- getStorageId(instanceId: string): any;
34
+ _newSecuritySDKByScene(securityConfig: InitSecurityConfig, successCallback?: () => void, failCallback?: (errMsg?: string) => void): Security;
22
35
  /**
23
- * @description init initSecurity SDK
36
+ * @description Obtain risk control configuration in local storage
24
37
  */
25
- initSecurity(securityConfig: IsecurityConfig): void;
38
+ private getSecurityConfigStorage;
26
39
  /**
27
40
  * @description Set the sdk basic configuration
28
41
  */
@@ -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
@@ -13,4 +13,13 @@ export declare class AMSCheckout extends AMSComponent {
13
13
  export declare class AMSAutoDebit extends AMSCheckout {
14
14
  constructor(options: IoptionsParams);
15
15
  }
16
+ export declare class AMSEasyPay extends AMSCheckout {
17
+ constructor(options: IoptionsParams);
18
+ }
19
+ export declare class AMSCashierPayment extends AMSCheckout {
20
+ constructor(options: IoptionsParams);
21
+ }
22
+ export declare class AMSVaulting extends AMSCheckout {
23
+ constructor(options: IoptionsParams);
24
+ }
16
25
  export default AMSCheckout;
package/esm/index.js CHANGED
@@ -38,4 +38,31 @@ export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
38
38
  }
39
39
  return _createClass(AMSAutoDebit);
40
40
  }(AMSCheckout);
41
+ export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
42
+ _inherits(AMSEasyPay, _AMSCheckout2);
43
+ var _super3 = _createSuper(AMSEasyPay);
44
+ function AMSEasyPay(options) {
45
+ _classCallCheck(this, AMSEasyPay);
46
+ return _super3.call(this, options);
47
+ }
48
+ return _createClass(AMSEasyPay);
49
+ }(AMSCheckout);
50
+ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
51
+ _inherits(AMSCashierPayment, _AMSCheckout3);
52
+ var _super4 = _createSuper(AMSCashierPayment);
53
+ function AMSCashierPayment(options) {
54
+ _classCallCheck(this, AMSCashierPayment);
55
+ return _super4.call(this, options);
56
+ }
57
+ return _createClass(AMSCashierPayment);
58
+ }(AMSCheckout);
59
+ export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
60
+ _inherits(AMSVaulting, _AMSCheckout4);
61
+ var _super5 = _createSuper(AMSVaulting);
62
+ function AMSVaulting(options) {
63
+ _classCallCheck(this, AMSVaulting);
64
+ return _super5.call(this, options);
65
+ }
66
+ return _createClass(AMSVaulting);
67
+ }(AMSCheckout);
41
68
  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,7 +17,6 @@ export default class ComponentApp {
17
17
  private _appVersion;
18
18
  private _isRetention;
19
19
  private _actionQueryPromise;
20
- private _actionSubmitPromise;
21
20
  private _renderParams;
22
21
  private _componentSign;
23
22
  private _appLocationSearch;
@@ -36,7 +35,7 @@ export default class ComponentApp {
36
35
  * @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
36
  */
38
37
  setRender(renderFunc: IrenderFuncParams): void;
39
- private initAPSecurity;
38
+ private initSecurity;
40
39
  private logDeviceId;
41
40
  private getDeviceIdAndLog;
42
41
  /**
@@ -50,7 +49,6 @@ export default class ComponentApp {
50
49
  * @description Interface request
51
50
  */
52
51
  private createActionQueryPromise;
53
- private createSubmitPromise;
54
52
  private cleanElement;
55
53
  /**
56
54
  * @description Create app