@alipay/ams-checkout 1.25.0 → 1.25.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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- 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 +7 -1
- package/esm/foundation/service/event-center.js +35 -4
- package/esm/index.d.ts +1 -0
- package/esm/index.js +5 -0
- package/package.json +1 -1
package/esm/config/index.d.ts
CHANGED
@@ -5,10 +5,10 @@ export declare const sdkVersion: string;
|
|
5
5
|
/**
|
6
6
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
7
7
|
*/
|
8
|
-
export declare const AMSCheckoutAppVersion = "1.25.
|
9
|
-
export declare const AMSAutoDebitAppVersion = "1.25.
|
10
|
-
export declare const AMSEasyPayAppVersion = "1.25.
|
11
|
-
export declare const AMSCashierPaymentAppVersion = "1.25.
|
12
|
-
export declare const AMSVaultingAppVersion = "1.25.
|
13
|
-
export declare const AMSPaymentElementAppVersion = "1.25.
|
14
|
-
export declare const ADDRESSElementAppVersion = "1.25.
|
8
|
+
export declare const AMSCheckoutAppVersion = "1.25.2";
|
9
|
+
export declare const AMSAutoDebitAppVersion = "1.25.2";
|
10
|
+
export declare const AMSEasyPayAppVersion = "1.25.2";
|
11
|
+
export declare const AMSCashierPaymentAppVersion = "1.25.2";
|
12
|
+
export declare const AMSVaultingAppVersion = "1.25.2";
|
13
|
+
export declare const AMSPaymentElementAppVersion = "1.25.2";
|
14
|
+
export declare const ADDRESSElementAppVersion = "1.25.2";
|
package/esm/config/index.js
CHANGED
@@ -35,10 +35,10 @@ export var sdkVersion = json.version;
|
|
35
35
|
/**
|
36
36
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
37
37
|
*/
|
38
|
-
export var AMSCheckoutAppVersion = '1.25.
|
39
|
-
export var AMSAutoDebitAppVersion = '1.25.
|
40
|
-
export var AMSEasyPayAppVersion = '1.25.
|
41
|
-
export var AMSCashierPaymentAppVersion = '1.25.
|
42
|
-
export var AMSVaultingAppVersion = '1.25.
|
43
|
-
export var AMSPaymentElementAppVersion = '1.25.
|
44
|
-
export var ADDRESSElementAppVersion = '1.25.
|
38
|
+
export var AMSCheckoutAppVersion = '1.25.2'; // 兜底版本号
|
39
|
+
export var AMSAutoDebitAppVersion = '1.25.2'; // 代扣
|
40
|
+
export var AMSEasyPayAppVersion = '1.25.2'; // easypay
|
41
|
+
export var AMSCashierPaymentAppVersion = '1.25.2'; // 收银台(卡、apm)
|
42
|
+
export var AMSVaultingAppVersion = '1.25.2'; // 绑卡
|
43
|
+
export var AMSPaymentElementAppVersion = '1.25.2'; // payment element
|
44
|
+
export var ADDRESSElementAppVersion = '1.25.2'; // address element
|
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,12 +27,17 @@ 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.
|
33
37
|
* @param e - The message event.
|
34
38
|
*/
|
35
39
|
private handleAppMessage;
|
40
|
+
private checkEventCompliant;
|
36
41
|
/**
|
37
42
|
* Processes the application message and emits the associated event.
|
38
43
|
* @param data - Parsed EventPayload from the app.
|
@@ -42,8 +47,9 @@ export declare class EventCenter implements Service {
|
|
42
47
|
* Listens to an event by adding a callback function.
|
43
48
|
* @param name - The name of the event to listen for.
|
44
49
|
* @param func - The callback function to execute when the event is emitted.
|
50
|
+
* @param isAppend - Append to event handlers as chain, default value is false
|
45
51
|
*/
|
46
|
-
listen(name: string, func: IListener): void;
|
52
|
+
listen(name: string, func: IListener, isAppend?: boolean): void;
|
47
53
|
/**
|
48
54
|
* Unsubscribes from an event. If a function is provided, only that function is removed.
|
49
55
|
* @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,15 +108,35 @@ 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 (!this.checkEventCompliant(eventPayload)) {
|
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
|
}
|
110
119
|
}
|
120
|
+
}, {
|
121
|
+
key: "checkEventCompliant",
|
122
|
+
value: function checkEventCompliant(eventPayload) {
|
123
|
+
// connect element场景下,多子iframes共用AntomCore中生成的instanceId,此时将发送事件方instanceId与iframes中instanceId做比较看是否在其中
|
124
|
+
// 非connect场景下,直接将发送事件方instanceId与AntomCore的instanceId做比较
|
125
|
+
if (eventPayload.name !== MessageName.APP_TO_SDK) {
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
var iframesInstanceIds = this.iframes.map(function (iframe) {
|
129
|
+
var _iframe$ref;
|
130
|
+
if (!new URL((_iframe$ref = iframe.ref) === null || _iframe$ref === void 0 ? void 0 : _iframe$ref.src)) {
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
return new URL(iframe.ref.src).searchParams.get('instanceId');
|
134
|
+
}).filter(Boolean);
|
135
|
+
if (eventPayload.instanceId !== this.instanceId && !iframesInstanceIds.includes(eventPayload.instanceId)) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
return true;
|
139
|
+
}
|
111
140
|
|
112
141
|
/**
|
113
142
|
* Processes the application message and emits the associated event.
|
@@ -126,11 +155,13 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
126
155
|
* Listens to an event by adding a callback function.
|
127
156
|
* @param name - The name of the event to listen for.
|
128
157
|
* @param func - The callback function to execute when the event is emitted.
|
158
|
+
* @param isAppend - Append to event handlers as chain, default value is false
|
129
159
|
*/
|
130
160
|
}, {
|
131
161
|
key: "listen",
|
132
162
|
value: function listen(name, func) {
|
133
|
-
var
|
163
|
+
var isAppend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
164
|
+
var eventList = isAppend ? this.events.get(name) || [] : [];
|
134
165
|
eventList.push({
|
135
166
|
func: func
|
136
167
|
});
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED