@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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/constant/index.d.ts +4 -0
- package/esm/constant/index.js +5 -0
- package/esm/foundation/core/index.d.ts +1 -0
- package/esm/foundation/core/index.js +28 -11
- package/esm/foundation/service/container/index.js +2 -0
- package/esm/foundation/service/event-center.d.ts +6 -1
- package/esm/foundation/service/event-center.js +15 -4
- package/esm/index.d.ts +1 -0
- package/esm/index.js +5 -0
- package/package.json +1 -1
package/esm/constant/index.d.ts
CHANGED
package/esm/constant/index.js
CHANGED
@@ -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'
|
@@ -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.
|
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.
|
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
|
103
|
-
if (
|
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(
|
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
|
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
package/esm/index.js
CHANGED