@alipay/ams-checkout 0.0.1710840616-dev.0 → 0.0.1711691167-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.
Files changed (48) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/request.js +3 -3
  3. package/esm/core/bus/ability/callback.d.ts +9 -0
  4. package/esm/core/bus/ability/callback.js +55 -0
  5. package/esm/core/bus/ability/security.d.ts +10 -0
  6. package/esm/core/bus/ability/security.js +104 -0
  7. package/esm/core/bus/ability/tracker.d.ts +9 -0
  8. package/esm/core/bus/ability/tracker.js +77 -0
  9. package/esm/core/bus/index.d.ts +125 -0
  10. package/esm/core/bus/index.js +366 -0
  11. package/esm/core/bus/interface.d.ts +36 -0
  12. package/esm/core/bus/interface.js +40 -0
  13. package/esm/core/component/index.d.ts +15 -1
  14. package/esm/core/component/index.js +189 -26
  15. package/esm/core/instance/index.d.ts +12 -1
  16. package/esm/core/instance/index.js +55 -12
  17. package/esm/index.d.ts +0 -3
  18. package/esm/index.js +8 -18
  19. package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +27 -8
  20. package/esm/{core/applepay/index.js → plugin/applepay/component.js} +150 -180
  21. package/esm/plugin/applepay/index.d.ts +17 -0
  22. package/esm/plugin/applepay/index.js +117 -0
  23. package/esm/{common → plugin}/applepay/interface.d.ts +62 -3
  24. package/esm/plugin/applepay/interface.js +69 -0
  25. package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +13 -7
  26. package/esm/{common/applepay/index.js → plugin/applepay/service.js} +159 -41
  27. package/esm/plugin/component/index.d.ts +4 -3
  28. package/esm/plugin/component/index.js +98 -108
  29. package/esm/plugin/const.d.ts +2 -0
  30. package/esm/plugin/const.js +33 -0
  31. package/esm/plugin/paypal/index.d.ts +20 -0
  32. package/esm/plugin/paypal/index.js +377 -0
  33. package/esm/plugin/type.d.ts +33 -0
  34. package/esm/plugin/utils.d.ts +6 -0
  35. package/esm/plugin/utils.js +21 -0
  36. package/esm/request/index.d.ts +1 -1
  37. package/esm/request/index.js +14 -8
  38. package/esm/service/index.d.ts +1 -1
  39. package/esm/types/index.d.ts +108 -11
  40. package/esm/types/index.js +26 -1
  41. package/esm/util/index.d.ts +2 -1
  42. package/esm/util/index.js +4 -2
  43. package/esm/util/logger.d.ts +4 -0
  44. package/esm/util/logger.js +23 -3
  45. package/esm/util/versionCompare.d.ts +1 -3
  46. package/esm/util/versionCompare.js +0 -75
  47. package/package.json +1 -1
  48. /package/esm/{common/applepay/interface.js → plugin/type.js} +0 -0
@@ -1,4 +1,6 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
5
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -27,11 +29,18 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
29
  */
28
30
  import { v4 as uuid } from 'uuid';
29
31
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
32
+ import { ApplePayBusSubscriber } from "../../plugin/applepay";
30
33
  import ComponentApp from "../../plugin/component";
31
- import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
34
+ import { ExtendPlugin } from "../../plugin/const";
35
+ import { PaypalBusSubscriber } from "../../plugin/paypal";
36
+ import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
37
  import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
33
38
  import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
34
39
  import { getSecurityConfigStorageKey } from "../../util/security";
40
+ import { BusManager, BusMessage } from "../bus";
41
+ import { SDKCallbackBusSubscriber } from "../bus/ability/callback";
42
+ import { SecurityBusSubscriber } from "../bus/ability/security";
43
+ import { TrackerBusSubscriber } from "../bus/ability/tracker";
35
44
  import CoreInstance from "../instance/index";
36
45
  export var getComponentSign = function getComponentSign(params) {
37
46
  var _params$paymentSessio = params.paymentSessionConfig,
@@ -114,6 +123,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
114
123
  // Register Cashier Application Plug in
115
124
  _this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
116
125
  _this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
126
+ _this.registerBusAbility();
117
127
  return _this;
118
128
  }
119
129
  _createClass(AMSComponent, [{
@@ -188,6 +198,109 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
188
198
  localStorage.setItem('antom_checkout_previousChannel', JSON.stringify(previousChannel));
189
199
  }
190
200
  }
201
+
202
+ /**
203
+ * 初始化 Bus总线的能力
204
+ */
205
+ }, {
206
+ key: "registerBusAbility",
207
+ value: function registerBusAbility() {
208
+ var _this$originOptions,
209
+ _this2 = this;
210
+ BusManager.debugTrace(((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.environment) !== environmentEnum.prod, this.logger);
211
+ BusManager.clear();
212
+ BusManager.addInterceptor({
213
+ onPublishException: function onPublishException(message, e) {
214
+ _this2.logger.logError({
215
+ title: 'onBusPublishException'
216
+ }, _objectSpread(_objectSpread({}, message), {}, {
217
+ errorMessage: JSON.stringify(e)
218
+ }));
219
+ }
220
+ });
221
+ // subscribe basic ablility
222
+ BusManager.subscribe(new SDKCallbackBusSubscriber(function (state) {
223
+ var _this2$_componentApp;
224
+ (_this2$_componentApp = _this2._componentApp) === null || _this2$_componentApp === void 0 || (_this2$_componentApp = _this2$_componentApp.AMSSDK) === null || _this2$_componentApp === void 0 || _this2$_componentApp._eventCenter.emit(EVENT.eventCallback.name, state);
225
+ }));
226
+ BusManager.subscribe(new SecurityBusSubscriber(function (deviceIdParameter, isPolling) {
227
+ var _this2$_componentApp2;
228
+ return (_this2$_componentApp2 = _this2._componentApp) === null || _this2$_componentApp2 === void 0 ? void 0 : _this2$_componentApp2.getDeviceIdAndLog(deviceIdParameter, isPolling);
229
+ }));
230
+ BusManager.subscribe(new TrackerBusSubscriber(this.logger));
231
+ // subscribe plugin
232
+ BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
233
+ BusManager.subscribe(new PaypalBusSubscriber(this.logger));
234
+
235
+ // register bus plugin
236
+ ExtendPlugin.forEach(function (item) {
237
+ var _item$busActionNames;
238
+ if (item !== null && item !== void 0 && item.busSubscriber) {
239
+ BusManager.subscribe(item === null || item === void 0 ? void 0 : item.busSubscriber);
240
+ }
241
+ var paymentChannelMatcher = item.paymentChannelMatcher;
242
+ if (paymentChannelMatcher) {
243
+ _this2._registerPlugin(paymentChannelMatcher.paymentMethod, item.busActionNames);
244
+ }
245
+ var sessionMatcher = item.sessionMatcher;
246
+ if (sessionMatcher) {
247
+ var pluginKey = sessionMatcher.productScene + sessionMatcher.productSceneVersion + sessionMatcher.paymentMethodCategoryType;
248
+ if (sessionMatcher.paymentMethodTypes) {
249
+ sessionMatcher.paymentMethodTypes.forEach(function (paymentMethodType) {
250
+ var subPluginKey = pluginKey + paymentMethodType;
251
+ _this2._registerPlugin(subPluginKey, item.busActionNames);
252
+ });
253
+ } else {
254
+ _this2._registerPlugin(pluginKey, item.busActionNames);
255
+ }
256
+ }
257
+ var optInit = item === null || item === void 0 || (_item$busActionNames = item.busActionNames) === null || _item$busActionNames === void 0 ? void 0 : _item$busActionNames.optional_init;
258
+ if (optInit) {
259
+ BusManager.publish(new BusMessage(optInit, JSON.stringify(_this2.originOptions)));
260
+ }
261
+ });
262
+ }
263
+
264
+ /**
265
+ * To determine whether the corresponding payment method is available,
266
+ * only the channel described in the document will be called, and it will be returned as available by default
267
+ * @param paymentMethod - described in the document
268
+ * @param subPaymentMethod - described in the document
269
+ * @returns
270
+ */
271
+ }, {
272
+ key: "canMakePayments",
273
+ value: function canMakePayments(paymentMethod, subPaymentMethod) {
274
+ var _this3 = this;
275
+ // 判断支付方式是否可用
276
+ return new Promise(function (resolve) {
277
+ var _this3$_getPlugin;
278
+ if (!paymentMethod) {
279
+ return resolve(true);
280
+ }
281
+ var actionName = (_this3$_getPlugin = _this3._getPlugin(paymentMethod)) === null || _this3$_getPlugin === void 0 ? void 0 : _this3$_getPlugin.canMakePayments;
282
+ if (actionName && BusManager.isSubscribed(actionName)) {
283
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
284
+ paymentMethod: paymentMethod,
285
+ subPaymentMethod: subPaymentMethod
286
+ })), {
287
+ fallback: false
288
+ }).then(function (message) {
289
+ resolve(message.getJSONObject());
290
+ }).catch(function (e) {
291
+ _this3.logger.logInfo({
292
+ title: 'canMakePayments_error'
293
+ }, {
294
+ params: JSON.stringify(e)
295
+ });
296
+ resolve(false);
297
+ });
298
+ } else {
299
+ resolve(true);
300
+ }
301
+ });
302
+ }
303
+
191
304
  /**
192
305
  * @description Create component application
193
306
  * @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.
@@ -195,7 +308,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
195
308
  }, {
196
309
  key: "createComponent",
197
310
  value: function createComponent(params) {
198
- var _this2 = this;
311
+ var _this4 = this;
199
312
  this.clearPreloadIframe();
200
313
  return this.parameterInitAndCheck({
201
314
  params: params,
@@ -203,23 +316,41 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
203
316
  }).then(function (_params) {
204
317
  return handleParams(_params);
205
318
  }).catch(function (error) {
206
- _this2.logger.logError({
319
+ _this4.logger.logError({
207
320
  title: 'sdk_error_parameter'
208
321
  }, {
209
322
  params: JSON.stringify(params)
210
323
  }).send();
211
- _this2._eventCenter.emit(EVENT.error.name, error);
324
+ _this4._eventCenter.emit(EVENT.error.name, error);
212
325
  return Promise.reject(error);
213
326
  }).then(function (appendParams) {
214
327
  var iframeNodesParams = appendParams.iframeNodesParams;
215
- _this2.savePreviousChannel(iframeNodesParams);
216
- return _this2.pluginAppendIframe(appendParams);
328
+ _this4.logger.setTrackId(iframeNodesParams === null || iframeNodesParams === void 0 ? void 0 : iframeNodesParams.sessionData);
329
+ return _this4.createComponentProcess(appendParams);
217
330
  });
218
331
  }
332
+ }, {
333
+ key: "createComponentProcess",
334
+ value: function createComponentProcess(appendParams) {
335
+ var _this$getBusActionNam;
336
+ this._appendParams = appendParams;
337
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.createComponent;
338
+ if (actionName && BusManager.isSubscribed(actionName)) {
339
+ // 执行出错了,在通用拦截器返回
340
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
341
+ appendParams: appendParams,
342
+ options: this.originOptions
343
+ })));
344
+ return Promise.resolve();
345
+ }
346
+ var iframeNodesParams = appendParams.iframeNodesParams;
347
+ this.savePreviousChannel(iframeNodesParams);
348
+ return this.pluginAppendIframe(appendParams);
349
+ }
219
350
  }, {
220
351
  key: "preloadComponent",
221
352
  value: function preloadComponent(channelType, productSceneVersion) {
222
- var _this3 = this;
353
+ var _this5 = this;
223
354
  this.channelType = channelType;
224
355
  this.productSceneVersion = productSceneVersion;
225
356
  var MAX_CLEAR_TIME = 10000;
@@ -235,7 +366,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
235
366
  });
236
367
  }
237
368
  setTimeout(function () {
238
- _this3.clearPreloadIframe(true);
369
+ _this5.clearPreloadIframe(true);
239
370
  }, MAX_CLEAR_TIME);
240
371
  }
241
372
  }, {
@@ -266,7 +397,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
266
397
  }, {
267
398
  key: "mountComponent",
268
399
  value: function mountComponent(params, selector) {
269
- var _this4 = this;
400
+ var _this6 = this;
270
401
  this.clearPreloadIframe();
271
402
  return this.parameterInitAndCheck({
272
403
  params: params,
@@ -275,19 +406,38 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
275
406
  }).then(function (_params) {
276
407
  return handleParams(_params);
277
408
  }).catch(function (error) {
278
- _this4.logger.logError({
409
+ _this6.logger.logError({
279
410
  title: 'sdk_error_parameter'
280
411
  }, {
281
412
  params: JSON.stringify(params)
282
413
  }).send();
283
- _this4._eventCenter.emit(EVENT.error.name, error);
414
+ _this6._eventCenter.emit(EVENT.error.name, error);
284
415
  return Promise.reject(error);
285
416
  }).then(function (appendParams) {
286
417
  var iframeNodesParams = appendParams.iframeNodesParams;
287
- _this4.savePreviousChannel(iframeNodesParams);
288
- return _this4.pluginAppendIframe(appendParams);
418
+ _this6.logger.setTrackId(iframeNodesParams === null || iframeNodesParams === void 0 ? void 0 : iframeNodesParams.sessionData);
419
+ return _this6.mountComponentProcess(appendParams);
289
420
  });
290
421
  }
422
+ }, {
423
+ key: "mountComponentProcess",
424
+ value: function mountComponentProcess(appendParams) {
425
+ var _this$getBusActionNam2;
426
+ this._appendParams = appendParams;
427
+ var actionName = (_this$getBusActionNam2 = this.getBusActionNames()) === null || _this$getBusActionNam2 === void 0 ? void 0 : _this$getBusActionNam2.mountComponent;
428
+ if (actionName && BusManager.isSubscribed(actionName)) {
429
+ // 执行出错了,在通用拦截器返回
430
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
431
+ appendParams: appendParams,
432
+ options: this.originOptions
433
+ })));
434
+ return Promise.resolve();
435
+ }
436
+ var iframeNodesParams = appendParams.iframeNodesParams;
437
+ this.savePreviousChannel(iframeNodesParams);
438
+ return this.pluginAppendIframe(appendParams);
439
+ }
440
+
291
441
  /**
292
442
  * @description Execute payment submission process
293
443
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
@@ -296,24 +446,37 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
296
446
  }, {
297
447
  key: "submit",
298
448
  value: function submit(data) {
299
- var _this5 = this;
449
+ var _this7 = this;
300
450
  return new Promise(function (resolve, reject) {
301
451
  try {
452
+ var _this7$getBusActionNa;
302
453
  var eventCallbackId = uuid();
303
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
- _this5._eventCenter.once(eventCallbackId, function (_data) {
305
- resolve(_data);
306
- });
307
- _this5._componentApp.dispatchToApp({
308
- context: {
309
- event: 'submitPay',
310
- eventCallbackId: eventCallbackId,
311
- data: data
312
- }
313
- });
314
- _this5.logger.logInfo({
454
+ _this7.logger.logInfo({
315
455
  title: 'sdk_event_apiSubmit'
316
456
  });
457
+ var actionName = (_this7$getBusActionNa = _this7.getBusActionNames()) === null || _this7$getBusActionNa === void 0 ? void 0 : _this7$getBusActionNa.submit;
458
+ if (actionName && BusManager.isSubscribed(actionName)) {
459
+ // 执行出错了,在通用拦截器返回
460
+ BusManager.publishForResult(new BusMessage(actionName, JSON.stringify({
461
+ appendParams: _this7._appendParams,
462
+ options: _this7.originOptions,
463
+ data: data
464
+ }))).then(function (busMessage) {
465
+ resolve(busMessage === null || busMessage === void 0 ? void 0 : busMessage.getJSONObject());
466
+ });
467
+ } else {
468
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
469
+ _this7._eventCenter.once(eventCallbackId, function (_data) {
470
+ resolve(_data);
471
+ });
472
+ _this7._componentApp.dispatchToApp({
473
+ context: {
474
+ event: 'submitPay',
475
+ eventCallbackId: eventCallbackId,
476
+ data: data
477
+ }
478
+ });
479
+ }
317
480
  } catch (error) {
318
481
  reject(error);
319
482
  }
@@ -1,13 +1,23 @@
1
- import type { AMSCheckoutOptions, InitSecurityConfig, IoptionsParams } from '../../types/index';
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
+ import { ComponentActionNamesType } from 'src/plugin/type';
9
+ import type { AMSCheckoutOptions, IAppendParams, InitSecurityConfig, IoptionsParams } from '../../types/index';
2
10
  import { EventCenter } from '../../util/index';
3
11
  import { Logger } from '../../util/logger';
4
12
  import { Security } from '../../util/security';
5
13
  export default class AMSSDK {
6
14
  options: AMSCheckoutOptions;
15
+ originOptions: IoptionsParams;
7
16
  logger: Logger;
8
17
  _eventCenter: EventCenter;
9
18
  _instanceId: string;
10
19
  _storageId: string;
20
+ _appendParams: IAppendParams;
11
21
  protected securitySdkMap: Map<string, Security>;
12
22
  protected plugins: Map<string, any>;
13
23
  constructor(options: IoptionsParams);
@@ -72,4 +82,5 @@ export default class AMSSDK {
72
82
  * @description Overlay Subscription
73
83
  */
74
84
  protected _overrideSubscription(name: string, func: any, funcKey: string): void;
85
+ protected getBusActionNames(): ComponentActionNamesType;
75
86
  }
@@ -16,6 +16,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
16
16
  * 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.
17
17
  */
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
+
19
20
  import { v4 as uuid } from 'uuid';
20
21
  import { sdkVersion } from "../../config/index";
21
22
  import { ERRORMESSAGE, EVENT } from "../../constant";
@@ -24,19 +25,23 @@ import { environmentEnum, modeEnum, networkModeEnum, osTypeEnum, productSceneEnu
24
25
  import { checkTimeElapsed, device, EventCenter, getOrSetStorageId, getType, queryParse, safeJson } from "../../util/index";
25
26
  import CallApp from "../../util/intl-callapp/es/main";
26
27
  import { LogConfig, Logger } from "../../util/logger";
27
- import { compareVersion } from "../../util/versionCompare";
28
28
  import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum } from "../../util/security";
29
+ import { compareVersion } from "../../util/versionCompare";
30
+ import { BusManager, BusMessage } from "../bus";
29
31
  var AMSSDK = /*#__PURE__*/function () {
30
32
  function AMSSDK(options) {
31
33
  _classCallCheck(this, AMSSDK);
32
34
  _defineProperty(this, "options", void 0);
35
+ _defineProperty(this, "originOptions", void 0);
33
36
  _defineProperty(this, "logger", void 0);
34
37
  _defineProperty(this, "_eventCenter", void 0);
35
38
  _defineProperty(this, "_instanceId", void 0);
36
39
  _defineProperty(this, "_storageId", void 0);
40
+ _defineProperty(this, "_appendParams", void 0);
37
41
  _defineProperty(this, "securitySdkMap", void 0);
38
42
  _defineProperty(this, "plugins", void 0);
39
43
  this._instanceId = uuid();
44
+ this.originOptions = options;
40
45
  this.options = {};
41
46
  this._eventCenter = new EventCenter();
42
47
  this._initEvent(options);
@@ -52,14 +57,16 @@ var AMSSDK = /*#__PURE__*/function () {
52
57
  this._storageId = _storageId;
53
58
 
54
59
  // TODO Consumption data analysis control parameters
55
- this.logger = new Logger(LogConfig, ![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
60
+ this.logger = new Logger(LogConfig, (options === null || options === void 0 ? void 0 : options.environment) !== environmentEnum.prod);
56
61
  this.logger.setMedta({
57
62
  instanceId: this._instanceId
58
63
  });
59
64
  this.logger.initTracker();
65
+ this.logger.setComponentStartTime(Date.now());
66
+ this.logger.setTrackId(this._instanceId);
60
67
  this.logger.logInfo({
61
68
  title: 'NEW_AMSSDK_BY_MECHANT',
62
- msg: "".concat(options === null || options === void 0 ? void 0 : options.environment, "_").concat(options === null || options === void 0 ? void 0 : options.locale, "}")
69
+ msg: "".concat(options === null || options === void 0 ? void 0 : options.environment, "_").concat(options === null || options === void 0 ? void 0 : options.locale)
63
70
  }).send();
64
71
  this.preInitSecurity();
65
72
  }
@@ -101,17 +108,29 @@ var AMSSDK = /*#__PURE__*/function () {
101
108
  }, {
102
109
  key: "unmount",
103
110
  value: function unmount() {
111
+ var _this$getBusActionNam;
104
112
  this.logger.logInfo({
105
113
  title: 'sdk_event_apiOnDestroy'
106
114
  }).send();
115
+ var actionName = (_this$getBusActionNam = this.getBusActionNames()) === null || _this$getBusActionNam === void 0 ? void 0 : _this$getBusActionNam.destroyComponent;
116
+ if (actionName && BusManager.isSubscribed(actionName)) {
117
+ var _this$_appendParams;
118
+ // 执行出错了,在通用拦截器返回
119
+ BusManager.publish(new BusMessage(actionName, JSON.stringify({
120
+ options: this.originOptions,
121
+ selector: (_this$_appendParams = this._appendParams) === null || _this$_appendParams === void 0 || (_this$_appendParams = _this$_appendParams.iframeNodesParams) === null || _this$_appendParams === void 0 ? void 0 : _this$_appendParams.selector
122
+ })));
123
+ }
107
124
  var _iterator = _createForOfIteratorHelper(this.plugins.values()),
108
125
  _step;
109
126
  try {
110
127
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
111
128
  var plugin = _step.value;
112
129
  try {
113
- plugin.logoutPlugin();
114
- // eslint-disable-next-line no-empty
130
+ if (plugin.logoutPlugin) {
131
+ plugin.logoutPlugin();
132
+ // eslint-disable-next-line no-empty
133
+ }
115
134
  } catch (error) {
116
135
  console.error(error);
117
136
  }
@@ -301,12 +320,14 @@ var AMSSDK = /*#__PURE__*/function () {
301
320
  key: "_registerPlugin",
302
321
  value: function _registerPlugin(pluginId, plugin) {
303
322
  this.plugins.set(pluginId, plugin);
304
- try {
305
- plugin.applyPlugin(this);
306
- } catch (error) {
307
- this.plugins.delete(pluginId);
308
- if (getType(error) === 'error') throw error;
309
- throw new Error("Failed to register plug-in\uFF1A".concat(pluginId, " Exception in the apply function of the plug-in"));
323
+ if (plugin !== null && plugin !== void 0 && plugin.applyPlugin) {
324
+ try {
325
+ plugin.applyPlugin(this);
326
+ } catch (error) {
327
+ this.plugins.delete(pluginId);
328
+ if (getType(error) === 'error') throw error;
329
+ throw new Error("Failed to register plug-in\uFF1A".concat(pluginId, " Exception in the apply function of the plug-in"));
330
+ }
310
331
  }
311
332
  }
312
333
  /**
@@ -316,11 +337,12 @@ var AMSSDK = /*#__PURE__*/function () {
316
337
  key: "_getPlugin",
317
338
  value: function _getPlugin(pluginId) {
318
339
  if (!this.plugins.has(pluginId)) {
319
- console.warn("".concat(pluginId, "Plugin unregistered"));
340
+ console.warn("".concat(pluginId, " Plugin unregistered"));
320
341
  return null;
321
342
  }
322
343
  return this.plugins.get(pluginId);
323
344
  }
345
+
324
346
  /**
325
347
  * @description Execute to open app or jump link
326
348
  */
@@ -381,6 +403,27 @@ var AMSSDK = /*#__PURE__*/function () {
381
403
  this._eventCenter.off(name, func, funcKey);
382
404
  this._eventCenter.on(name, func, funcKey);
383
405
  }
406
+ }, {
407
+ key: "getBusActionNames",
408
+ value: function getBusActionNames() {
409
+ var _appendParams$iframeN;
410
+ var appendParams = this._appendParams;
411
+ if (!appendParams) {
412
+ return null;
413
+ }
414
+ var actionNames = null;
415
+ var paymentSessionConfig = appendParams === null || appendParams === void 0 || (_appendParams$iframeN = appendParams.iframeNodesParams) === null || _appendParams$iframeN === void 0 || (_appendParams$iframeN = _appendParams$iframeN.paymentSessionMetaData) === null || _appendParams$iframeN === void 0 ? void 0 : _appendParams$iframeN.paymentSessionConfig;
416
+ if (paymentSessionConfig) {
417
+ var _appendParams$iframeN2;
418
+ var pluginKey = paymentSessionConfig.productScene + paymentSessionConfig.productSceneVersion + paymentSessionConfig.paymentMethodCategoryType;
419
+ var paymentMethodType = appendParams === null || appendParams === void 0 || (_appendParams$iframeN2 = appendParams.iframeNodesParams) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionMetaData) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionFactor) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentMethodInfo) === null || _appendParams$iframeN2 === void 0 ? void 0 : _appendParams$iframeN2.paymentMethodType;
420
+ if (paymentMethodType) {
421
+ pluginKey = pluginKey + paymentMethodType;
422
+ }
423
+ actionNames = this._getPlugin(pluginKey);
424
+ }
425
+ return actionNames;
426
+ }
384
427
  }]);
385
428
  return AMSSDK;
386
429
  }();
package/esm/index.d.ts CHANGED
@@ -5,15 +5,12 @@
5
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
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
7
  */
8
- import ApplePayComponent from './core/applepay';
9
8
  import { AMSComponent } from './core/component/index';
10
9
  import { IoptionsParams, componentSignEnum } from './types';
11
10
  export * from './types';
12
11
  export declare class AMSCheckout extends AMSComponent {
13
12
  constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
14
13
  }
15
- export declare class AMSApplePay extends ApplePayComponent {
16
- }
17
14
  export declare class AMSAutoDebit extends AMSCheckout {
18
15
  constructor(options: IoptionsParams);
19
16
  }
package/esm/index.js CHANGED
@@ -18,7 +18,6 @@ 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 ApplePayComponent from "./core/applepay";
22
21
  import { AMSComponent } from "./core/component/index";
23
22
  import { componentSignEnum } from "./types";
24
23
  import { productSceneEnum } from "./types/index";
@@ -38,30 +37,21 @@ export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
38
37
  }
39
38
  return _createClass(AMSCheckout);
40
39
  }(AMSComponent);
41
- export var AMSApplePay = /*#__PURE__*/function (_ApplePayComponent) {
42
- _inherits(AMSApplePay, _ApplePayComponent);
43
- var _super2 = _createSuper(AMSApplePay);
44
- function AMSApplePay() {
45
- _classCallCheck(this, AMSApplePay);
46
- return _super2.apply(this, arguments);
47
- }
48
- return _createClass(AMSApplePay);
49
- }(ApplePayComponent);
50
40
  export var AMSAutoDebit = /*#__PURE__*/function (_AMSCheckout) {
51
41
  _inherits(AMSAutoDebit, _AMSCheckout);
52
- var _super3 = _createSuper(AMSAutoDebit);
42
+ var _super2 = _createSuper(AMSAutoDebit);
53
43
  function AMSAutoDebit(options) {
54
44
  _classCallCheck(this, AMSAutoDebit);
55
45
  var _options = Object.assign({}, options, {
56
46
  product: productSceneEnum.AUTO_DEBIT
57
47
  });
58
- return _super3.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
48
+ return _super2.call(this, _options, [componentSignEnum.AUTO_DEBIT_WALLET]);
59
49
  }
60
50
  return _createClass(AMSAutoDebit);
61
51
  }(AMSCheckout);
62
52
  export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
63
53
  _inherits(AMSEasyPay, _AMSCheckout2);
64
- var _super4 = _createSuper(AMSEasyPay);
54
+ var _super3 = _createSuper(AMSEasyPay);
65
55
  function AMSEasyPay(options) {
66
56
  _classCallCheck(this, AMSEasyPay);
67
57
  var _options = Object.assign({}, options, {
@@ -86,13 +76,13 @@ export var AMSEasyPay = /*#__PURE__*/function (_AMSCheckout2) {
86
76
  error: error
87
77
  });
88
78
  }
89
- return _super4.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
79
+ return _super3.call(this, _options, [componentSignEnum.EASY_PAY_WALLET], currentProductSceneVersion);
90
80
  }
91
81
  return _createClass(AMSEasyPay);
92
82
  }(AMSCheckout);
93
83
  export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
94
84
  _inherits(AMSCashierPayment, _AMSCheckout3);
95
- var _super5 = _createSuper(AMSCashierPayment);
85
+ var _super4 = _createSuper(AMSCashierPayment);
96
86
  function AMSCashierPayment(options) {
97
87
  _classCallCheck(this, AMSCashierPayment);
98
88
  var _options = Object.assign({}, options, {
@@ -117,19 +107,19 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout3) {
117
107
  error: error
118
108
  });
119
109
  }
120
- return _super5.call(this, _options, currentChannelType);
110
+ return _super4.call(this, _options, currentChannelType);
121
111
  }
122
112
  return _createClass(AMSCashierPayment);
123
113
  }(AMSCheckout);
124
114
  export var AMSVaulting = /*#__PURE__*/function (_AMSCheckout4) {
125
115
  _inherits(AMSVaulting, _AMSCheckout4);
126
- var _super6 = _createSuper(AMSVaulting);
116
+ var _super5 = _createSuper(AMSVaulting);
127
117
  function AMSVaulting(options) {
128
118
  _classCallCheck(this, AMSVaulting);
129
119
  var _options = Object.assign({}, options, {
130
120
  product: productSceneEnum.VAULTING
131
121
  });
132
- return _super6.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
122
+ return _super5.call(this, _options, [componentSignEnum.CASHIER_PAYMENT_CARD]);
133
123
  }
134
124
  return _createClass(AMSVaulting);
135
125
  }(AMSCheckout);
@@ -5,27 +5,46 @@
5
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
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
7
  */
8
- import { IApplePayOptionsParams } from '../../types';
9
- import CoreInstance from '../instance';
8
+ import { ApplePaySubTypeEnum, IAppendParams, IApplePayOptionsParams } from '../../types';
9
+ import type { Logger } from '../../util/logger';
10
+ export declare enum ApplePayComponentEvent {
11
+ sdk_event_appleAvailable = "sdk_event_appleAvailable",
12
+ sdk_event_appleCreateComponent = "sdk_event_appleCreateComponent",
13
+ sdk_event_appleShowPaymentSheet = "sdk_event_appleShowPaymentSheet",
14
+ sdk_event_appleOnvalidatemerchant = "sdk_event_appleOnvalidatemerchant",
15
+ sdk_event_appleSubmitToken = "sdk_event_appleSubmitToken",
16
+ sdk_event_applePaymentResult = "sdk_event_applePaymentResult",
17
+ sdk_event_appleDestroyComponent = "sdk_event_appleDestroyComponent"
18
+ }
10
19
  /**
11
20
  * Apple pay Component
12
21
  */
13
- declare class ApplePayComponent extends CoreInstance {
22
+ declare class ApplePayComponent {
14
23
  private _applePayService;
15
24
  private _parseData;
16
25
  private _sessionData;
17
26
  private _isFinish;
18
- constructor(options: IApplePayOptionsParams);
19
- private getDeviceIdAndLog;
20
- private logDeviceId;
27
+ private _options;
28
+ private logger;
29
+ private isRecurring;
30
+ constructor(options: IApplePayOptionsParams, logger: Logger);
31
+ /**
32
+ * Is Apple Pay Enabled
33
+ * @param subTypeEnum
34
+ * @returns
35
+ */
36
+ canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): boolean;
21
37
  /**
22
38
  * Is Apple Pay Enabled
39
+ * @param subTypeEnum
40
+ * @returns
23
41
  */
24
- isAppPayEnabled(): boolean;
42
+ isAppPayEnabled(subTypeEnum?: ApplePaySubTypeEnum): boolean;
43
+ private onEventCallback;
25
44
  /**
26
45
  * Submit Pay
27
46
  * @param paymentSessionData
28
47
  */
29
- submitPay(paymentSessionData: string): void;
48
+ submitPay(appendParams: IAppendParams): void;
30
49
  }
31
50
  export default ApplePayComponent;