@alipay/ams-checkout 1.25.0 → 1.25.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.
@@ -112,6 +112,10 @@ export declare const EVENT: {
112
112
  name: string;
113
113
  uniqueKey: string;
114
114
  };
115
+ closeCallback: {
116
+ name: string;
117
+ uniqueKey: string;
118
+ };
115
119
  eventCallback: {
116
120
  name: string;
117
121
  uniqueKey: string;
@@ -112,6 +112,11 @@ export var EVENT = {
112
112
  name: 'onClose',
113
113
  uniqueKey: 'userOnClose'
114
114
  },
115
+ // 标记 SDK 回调事件
116
+ closeCallback: {
117
+ name: 'onCloseCallback',
118
+ uniqueKey: 'closeCallback'
119
+ },
115
120
  eventCallback: {
116
121
  name: 'onEventCallback',
117
122
  uniqueKey: 'userEventCallback'
@@ -22,5 +22,6 @@ export declare class AntomSDKCore {
22
22
  getPaymentContext(): PaymentContext;
23
23
  destroy(): void;
24
24
  private handleBehaviorRender;
25
+ private handleClose;
25
26
  private cleanRender;
26
27
  }
@@ -10,7 +10,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
10
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- import { DisplayTypeEnum } from "../../types";
13
+ import { DisplayTypeEnum, eventCodeEnum } from "../../types";
14
14
  import { DisplayInfo } from "../index";
15
15
  import { v4 as uuid } from 'uuid';
16
16
  import { ServiceProvider } from "../service";
@@ -150,6 +150,18 @@ export var AntomSDKCore = /*#__PURE__*/function () {
150
150
  return _ref2.apply(this, arguments);
151
151
  };
152
152
  }());
153
+ eventCenter.listen(EVENT.closeCallback.name, function () {
154
+ var _options$onClose;
155
+ (_options$onClose = options.onClose) === null || _options$onClose === void 0 || _options$onClose.call(options);
156
+ });
157
+ eventCenter.listen(EVENT.eventCallback.name, function (data) {
158
+ var _options$onEventCallb;
159
+ (_options$onEventCallb = options.onEventCallback) === null || _options$onEventCallb === void 0 || _options$onEventCallb.call(options, data);
160
+ });
161
+ eventCenter.listen(EVENT.error.name, function (data) {
162
+ var _options$onError;
163
+ (_options$onError = options.onError) === null || _options$onError === void 0 || _options$onError.call(options, data);
164
+ });
153
165
 
154
166
  // execute additional logic from specified product
155
167
  if (this.productProcessors[sdkMetaData.productScene]) {
@@ -291,11 +303,7 @@ export var AntomSDKCore = /*#__PURE__*/function () {
291
303
  showRetentionPopup();
292
304
  return;
293
305
  } else {
294
- _this2.cleanRender();
295
- eventCenter.dispatchToApp({
296
- event: EVENT.close.name,
297
- data: {}
298
- });
306
+ _this2.handleClose();
299
307
  }
300
308
  };
301
309
 
@@ -322,12 +330,8 @@ export var AntomSDKCore = /*#__PURE__*/function () {
322
330
  createRetentionPopup(platform, function () {
323
331
  hideRetentionPopup();
324
332
  }, function () {
325
- eventCenter.dispatchToApp({
326
- event: EVENT.close.name,
327
- data: {}
328
- });
329
333
  hideRetentionPopup();
330
- _this2.cleanRender();
334
+ _this2.handleClose();
331
335
  });
332
336
  createMockup({
333
337
  platform: platform,
@@ -337,6 +341,19 @@ export var AntomSDKCore = /*#__PURE__*/function () {
337
341
  return;
338
342
  }
339
343
  }
344
+ }, {
345
+ key: "handleClose",
346
+ value: function handleClose() {
347
+ var eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
348
+ eventCenter.emit(EVENT.closeCallback.name, {});
349
+ eventCenter.emit(EVENT.eventCallback.name, {
350
+ code: eventCodeEnum.SDK_PAYMENT_CANCEL,
351
+ result: {
352
+ result: {}
353
+ }
354
+ });
355
+ this.cleanRender();
356
+ }
340
357
  }, {
341
358
  key: "cleanRender",
342
359
  value: function cleanRender() {
@@ -82,6 +82,8 @@ export var ContainerService = /*#__PURE__*/function () {
82
82
  }
83
83
  var container = document.getElementById(COMPONENT_CONTAINER_ID);
84
84
  if (container) container === null || container === void 0 || container.remove();
85
+ this.webApp = null;
86
+ this.eventCenter.cleanIFrames();
85
87
 
86
88
  // animation
87
89
  (_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(displayInfo.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
@@ -27,6 +27,10 @@ export declare class EventCenter implements Service {
27
27
  * @param domain - The domain of the app.
28
28
  */
29
29
  addIFrame(iframe: HTMLIFrameElement): void;
30
+ /**
31
+ * Cleans iframes when web app close
32
+ */
33
+ cleanIFrames(): void;
30
34
  removeIFrame(iframe: HTMLIFrameElement): void;
31
35
  /**
32
36
  * Handles messages received from the app.
@@ -42,8 +46,9 @@ export declare class EventCenter implements Service {
42
46
  * Listens to an event by adding a callback function.
43
47
  * @param name - The name of the event to listen for.
44
48
  * @param func - The callback function to execute when the event is emitted.
49
+ * @param isAppend - Append to event handlers as chain, default value is false
45
50
  */
46
- listen(name: string, func: IListener): void;
51
+ listen(name: string, func: IListener, isAppend?: boolean): void;
47
52
  /**
48
53
  * Unsubscribes from an event. If a function is provided, only that function is removed.
49
54
  * @param name - The name of the event to unlisten to.
@@ -72,6 +72,15 @@ export var EventCenter = /*#__PURE__*/function () {
72
72
  origin: getIframeOrigin(iframe)
73
73
  });
74
74
  }
75
+
76
+ /**
77
+ * Cleans iframes when web app close
78
+ */
79
+ }, {
80
+ key: "cleanIFrames",
81
+ value: function cleanIFrames() {
82
+ this.iframes = [];
83
+ }
75
84
  }, {
76
85
  key: "removeIFrame",
77
86
  value: function removeIFrame(iframe) {
@@ -99,11 +108,11 @@ export var EventCenter = /*#__PURE__*/function () {
99
108
  }
100
109
  var isJson = isJsonString(e.data);
101
110
  if (isJson) {
102
- var _EventPayload = JSON.parse(e.data);
103
- if (_EventPayload.name !== MessageName.APP_TO_SDK) {
111
+ var eventPayload = JSON.parse(e.data);
112
+ if (eventPayload.name !== MessageName.APP_TO_SDK || eventPayload.instanceId !== this.instanceId) {
104
113
  return;
105
114
  }
106
- this._handleAppMessage(_EventPayload);
115
+ this._handleAppMessage(eventPayload);
107
116
  } else {
108
117
  console.error(ERRORMESSAGE.NOT_JSON_FORMAT);
109
118
  }
@@ -126,11 +135,13 @@ export var EventCenter = /*#__PURE__*/function () {
126
135
  * Listens to an event by adding a callback function.
127
136
  * @param name - The name of the event to listen for.
128
137
  * @param func - The callback function to execute when the event is emitted.
138
+ * @param isAppend - Append to event handlers as chain, default value is false
129
139
  */
130
140
  }, {
131
141
  key: "listen",
132
142
  value: function listen(name, func) {
133
- var eventList = this.events.get(name) || [];
143
+ var isAppend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
144
+ var eventList = isAppend ? this.events.get(name) || [] : [];
134
145
  eventList.push({
135
146
  func: func
136
147
  });
package/esm/index.d.ts CHANGED
@@ -33,4 +33,5 @@ export declare class AMSEasyPay {
33
33
  private core;
34
34
  constructor(options: IoptionsParams);
35
35
  createComponent(params: IcreateComponent): void;
36
+ unmount(): void;
36
37
  }
package/esm/index.js CHANGED
@@ -181,6 +181,11 @@ export var AMSEasyPay = /*#__PURE__*/function () {
181
181
  isAppWebview: params.isAppWebview
182
182
  });
183
183
  }
184
+ }, {
185
+ key: "unmount",
186
+ value: function unmount() {
187
+ this.core.destroy();
188
+ }
184
189
  }]);
185
190
  return AMSEasyPay;
186
191
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "1.25.0",
3
+ "version": "1.25.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",