@alipay/ams-checkout 0.0.1730107332-dev.4 → 0.0.1730107332-dev.40
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/component/channel.d.ts +2 -3
- package/esm/component/channel.js +63 -29
- package/esm/component/component.inline.style.js +1 -1
- package/esm/component/component.popup.style.d.ts +1 -3
- package/esm/component/component.popup.style.js +1 -3
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +10 -10
- package/esm/constant/index.d.ts +3 -0
- package/esm/constant/index.js +3 -0
- package/esm/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +125 -0
- package/esm/core/bus/index.js +366 -0
- package/esm/core/bus/interface.d.ts +36 -0
- package/esm/core/bus/interface.js +40 -0
- package/esm/core/component/address.d.ts +8 -0
- package/esm/core/component/address.js +72 -0
- package/esm/core/component/appPreloadProcessing.d.ts +1 -0
- package/esm/core/component/appPreloadProcessing.js +89 -0
- package/esm/core/component/ckp/index.d.ts +27 -0
- package/esm/core/component/ckp/index.js +167 -0
- package/esm/core/component/element/components/address.d.ts +19 -0
- package/esm/core/component/element/components/address.js +68 -0
- package/esm/core/component/element/components/auth.d.ts +17 -0
- package/esm/core/component/element/components/auth.js +60 -0
- package/esm/core/component/element/components/payment.d.ts +19 -0
- package/esm/core/component/element/components/payment.js +74 -0
- package/esm/core/component/element/index.d.ts +47 -0
- package/esm/core/component/element/index.js +816 -0
- package/esm/core/component/element/mock.d.ts +4 -0
- package/esm/core/component/element/mock.js +491 -0
- package/esm/core/component/element/type.d.ts +190 -0
- package/esm/core/component/element/type.js +35 -0
- package/esm/core/component/element/utils.d.ts +13 -0
- package/esm/core/component/element/utils.js +6 -0
- package/esm/core/component/index.d.ts +51 -0
- package/esm/core/component/index.js +531 -0
- package/esm/core/drop-in/index.d.ts +22 -0
- package/esm/core/drop-in/index.js +104 -0
- package/esm/core/instance/index.d.ts +89 -0
- package/esm/core/instance/index.js +499 -0
- package/esm/foundation/core/index.d.ts +3 -3
- package/esm/foundation/core/index.js +10 -8
- package/esm/foundation/index.d.ts +6 -5
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +6 -6
- package/esm/foundation/product-processor/easysafepay/deps.js +4 -4
- package/esm/foundation/product-processor/easysafepay/index.d.ts +2 -3
- package/esm/foundation/product-processor/easysafepay/index.js +110 -243
- package/esm/foundation/service/api-bus/index.d.ts +2 -2
- package/esm/foundation/service/container/index.d.ts +4 -2
- package/esm/foundation/service/container/index.js +43 -1
- package/esm/foundation/service/event-center.d.ts +6 -4
- package/esm/foundation/service/event-center.js +47 -17
- package/esm/foundation/service/global-data/index.d.ts +2 -2
- package/esm/foundation/service/index.d.ts +2 -2
- package/esm/foundation/service/log/index.d.ts +2 -2
- package/esm/foundation/service/log/index.js +1 -1
- package/esm/foundation/service/requester/deps.d.ts +1 -1
- package/esm/foundation/service/requester/requester.d.ts +2 -2
- package/esm/foundation/service/security/index.d.ts +2 -2
- package/esm/foundation/service/security/index.js +1 -0
- package/esm/foundation/utils/redirect_utils.d.ts +5 -0
- package/esm/foundation/utils/redirect_utils.js +205 -58
- package/esm/foundation/utils/system_events.js +0 -5
- package/esm/foundation/utils/web_app_url_utils.js +1 -1
- package/esm/index.d.ts +31 -2
- package/esm/index.js +146 -6
- package/esm/plugin/applepay/component.d.ts +50 -0
- package/esm/plugin/applepay/component.js +339 -0
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +117 -0
- package/esm/plugin/applepay/interface.d.ts +161 -0
- package/esm/plugin/applepay/interface.js +69 -0
- package/esm/plugin/applepay/service.d.ts +54 -0
- package/esm/plugin/applepay/service.js +289 -0
- package/esm/plugin/component/cashierApp.d.ts +36 -0
- package/esm/plugin/component/cashierApp.js +244 -0
- package/esm/plugin/component/channel.d.ts +21 -0
- package/esm/plugin/component/channel.js +89 -0
- package/esm/plugin/component/component.inline.style.d.ts +10 -0
- package/esm/plugin/component/component.inline.style.js +121 -0
- package/esm/plugin/component/component.popup.style.d.ts +16 -0
- package/esm/plugin/component/component.popup.style.js +174 -0
- package/esm/plugin/component/index.d.ts +127 -0
- package/esm/plugin/component/index.js +1896 -0
- package/esm/plugin/component/popupWindow.style.d.ts +11 -0
- package/esm/plugin/component/popupWindow.style.js +121 -0
- package/esm/plugin/const.d.ts +2 -0
- package/esm/plugin/const.js +33 -0
- package/esm/plugin/drop-in/index.d.ts +71 -0
- package/esm/plugin/drop-in/index.js +324 -0
- package/esm/plugin/payment-element/utils.d.ts +2 -0
- package/esm/plugin/payment-element/utils.js +6 -0
- package/esm/plugin/paypal/index.d.ts +20 -0
- package/esm/plugin/paypal/index.js +390 -0
- package/esm/plugin/type.d.ts +34 -0
- package/esm/plugin/type.js +1 -0
- package/esm/plugin/utils.d.ts +6 -0
- package/esm/plugin/utils.js +21 -0
- package/esm/service/element.d.ts +4 -0
- package/esm/service/element.js +51 -0
- package/esm/service/index.d.ts +1 -0
- package/esm/service/index.js +2 -0
- package/esm/types/index.d.ts +228 -26
- package/esm/types/index.js +54 -5
- package/esm/util/createIframeNode.d.ts +6 -0
- package/esm/util/createIframeNode.js +48 -0
- package/esm/util/getBackScheme.d.ts +2 -2
- package/esm/util/getBackScheme.js +2 -2
- package/esm/util/index.d.ts +11 -1
- package/esm/util/index.js +84 -3
- package/esm/util/intl-callapp/es/index.js +0 -1
- package/esm/util/security.d.ts +33 -0
- package/esm/util/security.js +182 -0
- package/package.json +2 -1
- package/esm/foundation/types/index.d.ts +0 -4
- package/esm/foundation/types/index.js +0 -4
@@ -13,7 +13,7 @@ import { addInlineLoading, createInlineBaseElement } from "../../../component/co
|
|
13
13
|
import { addPopupLoading, createBaseElement } from "../../../component/component.popup.style";
|
14
14
|
import { COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CONTAINER_ID, ERRORMESSAGE, LOADING_ID, MOCKUP_ID } from "../../../constant";
|
15
15
|
import { ServiceProvider } from "../index";
|
16
|
-
import { EVENT } from "../../../constant";
|
16
|
+
import { EVENT, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../../constant";
|
17
17
|
import { PopupManager } from "./popup";
|
18
18
|
/**
|
19
19
|
* @author 谦彧 <zhangmian.zm@alipay.com>
|
@@ -31,6 +31,7 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
31
31
|
_defineProperty(this, "logService", void 0);
|
32
32
|
_defineProperty(this, "displayInfo", void 0);
|
33
33
|
_defineProperty(this, "webApp", void 0);
|
34
|
+
_defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
|
34
35
|
// if this variable is true, SDK will invoke listener instead of showing loading
|
35
36
|
_defineProperty(this, "customizedLoadingListener", void 0);
|
36
37
|
}
|
@@ -181,6 +182,7 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
181
182
|
});
|
182
183
|
this.eventCenter.listen(EVENT.popupWindow.name, function (data) {
|
183
184
|
var _this2$displayInfo;
|
185
|
+
if (data.paymentElementOldModel) return;
|
184
186
|
_this2.popupManager.popup(_objectSpread({
|
185
187
|
platform: (_this2$displayInfo = _this2.displayInfo) === null || _this2$displayInfo === void 0 ? void 0 : _this2$displayInfo.platform
|
186
188
|
}, data)).catch(function (error) {
|
@@ -202,6 +204,9 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
202
204
|
this.eventCenter.listen(EVENT.hideCloseButton.name, function () {
|
203
205
|
_this2.changeCloseBtnVisibility(false);
|
204
206
|
});
|
207
|
+
this.eventCenter.listen(EVENT.appHeartBeat.name, function () {
|
208
|
+
_this2.handleAppHeartBeat();
|
209
|
+
});
|
205
210
|
}
|
206
211
|
}, {
|
207
212
|
key: "addCapabilityToApiBusManager",
|
@@ -241,6 +246,43 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
241
246
|
this.webApp.style.height = "".concat(data.height, "px");
|
242
247
|
}
|
243
248
|
}
|
249
|
+
}, {
|
250
|
+
key: "handleAppHeartBeat",
|
251
|
+
value: function handleAppHeartBeat() {
|
252
|
+
var _this3 = this;
|
253
|
+
try {
|
254
|
+
if (!this._webAppHeartBeatTimeoutFn) {
|
255
|
+
this._webAppHeartBeatTimeoutFn = function () {
|
256
|
+
if (_this3.webApp && _this3.displayInfo) {
|
257
|
+
_this3.logService.logError({
|
258
|
+
title: 'sdk_error_appHeartBeatTimeout'
|
259
|
+
});
|
260
|
+
}
|
261
|
+
};
|
262
|
+
}
|
263
|
+
if (window._webAppHeartBeatTimeoutId) {
|
264
|
+
clearTimeout(window._webAppHeartBeatTimeoutId);
|
265
|
+
window._webAppHeartBeatTimeoutId = null;
|
266
|
+
}
|
267
|
+
if (this._webAppHeartBeatTimeoutFn) {
|
268
|
+
window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
|
269
|
+
}
|
270
|
+
setTimeout(function () {
|
271
|
+
if (_this3.webApp && _this3.displayInfo) {
|
272
|
+
_this3.eventCenter.dispatchToApp({
|
273
|
+
event: 'sdkHeartBeat',
|
274
|
+
data: {}
|
275
|
+
});
|
276
|
+
}
|
277
|
+
}, TIME_DELAY_SEND_HEART_BEAT);
|
278
|
+
} catch (error) {
|
279
|
+
this.logService.logError({
|
280
|
+
title: 'sdk_error_handleAppHeartBeat'
|
281
|
+
}, {
|
282
|
+
errorMessage: error.message
|
283
|
+
});
|
284
|
+
}
|
285
|
+
}
|
244
286
|
}, {
|
245
287
|
key: "changeCloseBtnVisibility",
|
246
288
|
value: function changeCloseBtnVisibility(isShow) {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { EventPayload, EventPayloadContext,
|
1
|
+
import { EventPayload, EventPayloadContext, IoptionsParams } from '../../types';
|
2
2
|
import { SDKMetaData, Service } from '../index';
|
3
3
|
/**
|
4
4
|
* @author 江跃 <jiangbin.gjb@antgroup.com>
|
@@ -12,7 +12,7 @@ export declare class EventCenter implements Service {
|
|
12
12
|
/**
|
13
13
|
* Initializes the event center
|
14
14
|
*/
|
15
|
-
init(initOptions:
|
15
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
16
16
|
/**
|
17
17
|
* Cleans up event listeners when the event center is destroyed.
|
18
18
|
*/
|
@@ -27,6 +27,7 @@ export declare class EventCenter implements Service {
|
|
27
27
|
* @param domain - The domain of the app.
|
28
28
|
*/
|
29
29
|
addIFrame(iframe: HTMLIFrameElement): void;
|
30
|
+
removeIFrame(iframe: HTMLIFrameElement): void;
|
30
31
|
/**
|
31
32
|
* Handles messages received from the app.
|
32
33
|
* @param e - The message event.
|
@@ -54,13 +55,14 @@ export declare class EventCenter implements Service {
|
|
54
55
|
* @param name - The name of the event to emit.
|
55
56
|
* @param data - The event data to pass to the event listeners.
|
56
57
|
*/
|
57
|
-
emit(name: string, data: any,
|
58
|
+
emit(name: string, data: any, EventPayload?: EventPayload): void;
|
58
59
|
/**
|
59
60
|
* Registers a callback for an event and immediately dispatches the event to the app.
|
60
61
|
* @param payloadContext - The context containing event information and callback ID.
|
61
62
|
* @param func - The callback function to execute when the event is emitted.
|
62
63
|
*/
|
63
64
|
emitAndListen(payloadContext: EventPayloadContext, func: IListener): void;
|
65
|
+
queryParse(url?: string): Record<string, any>;
|
64
66
|
/**
|
65
67
|
* Dispatches the event payload to the app via postMessage.
|
66
68
|
* @param payloadContext - The context containing event to be dispatched.
|
@@ -69,6 +71,6 @@ export declare class EventCenter implements Service {
|
|
69
71
|
isExist(name: string): boolean;
|
70
72
|
}
|
71
73
|
interface IListener {
|
72
|
-
(data: any,
|
74
|
+
(data: any, EventPayload?: EventPayload): void;
|
73
75
|
}
|
74
76
|
export {};
|
@@ -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; }
|
@@ -7,7 +9,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
7
9
|
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); }
|
8
10
|
import { v4 as uuid } from 'uuid';
|
9
11
|
import { ERRORMESSAGE } from "../../constant";
|
10
|
-
import { MessageName } from "../../types";
|
12
|
+
import { EventPayload, MessageName } from "../../types";
|
11
13
|
import { isJsonString } from "../../util";
|
12
14
|
import { getIframeOrigin, registerSystemEvents, unRegisterSystemEvents } from "../utils/system_events";
|
13
15
|
|
@@ -70,6 +72,16 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
70
72
|
origin: getIframeOrigin(iframe)
|
71
73
|
});
|
72
74
|
}
|
75
|
+
}, {
|
76
|
+
key: "removeIFrame",
|
77
|
+
value: function removeIFrame(iframe) {
|
78
|
+
var index = this.iframes.findIndex(function (item) {
|
79
|
+
return item.origin === getIframeOrigin(iframe);
|
80
|
+
});
|
81
|
+
if (index !== -1) {
|
82
|
+
this.iframes.splice(index, 1);
|
83
|
+
}
|
84
|
+
}
|
73
85
|
|
74
86
|
/**
|
75
87
|
* Handles messages received from the app.
|
@@ -79,7 +91,6 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
79
91
|
key: "handleAppMessage",
|
80
92
|
value: function handleAppMessage(e) {
|
81
93
|
var _e$data;
|
82
|
-
// console.log('sdk received message:', e);
|
83
94
|
if (!this.iframes.some(function (iframe) {
|
84
95
|
return iframe.origin === e.origin;
|
85
96
|
})) return;
|
@@ -88,15 +99,13 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
88
99
|
}
|
89
100
|
var isJson = isJsonString(e.data);
|
90
101
|
if (isJson) {
|
91
|
-
var
|
92
|
-
|
93
|
-
if (_eventPayload.name !== MessageName.APP_TO_SDK) {
|
102
|
+
var _EventPayload = JSON.parse(e.data);
|
103
|
+
if (_EventPayload.name !== MessageName.APP_TO_SDK) {
|
94
104
|
return;
|
95
105
|
}
|
96
|
-
this._handleAppMessage(
|
106
|
+
this._handleAppMessage(_EventPayload);
|
97
107
|
} else {
|
98
|
-
console.
|
99
|
-
// TODO: 异常上报
|
108
|
+
console.error(ERRORMESSAGE.NOT_JSON_FORMAT);
|
100
109
|
}
|
101
110
|
}
|
102
111
|
|
@@ -106,11 +115,11 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
106
115
|
*/
|
107
116
|
}, {
|
108
117
|
key: "_handleAppMessage",
|
109
|
-
value: function _handleAppMessage(
|
110
|
-
var context =
|
118
|
+
value: function _handleAppMessage(EventPayload) {
|
119
|
+
var context = EventPayload.context;
|
111
120
|
var event = context.event,
|
112
121
|
data = context.data;
|
113
|
-
this.emit(event, data,
|
122
|
+
this.emit(event, data, EventPayload);
|
114
123
|
}
|
115
124
|
|
116
125
|
/**
|
@@ -156,11 +165,11 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
156
165
|
*/
|
157
166
|
}, {
|
158
167
|
key: "emit",
|
159
|
-
value: function emit(name, data,
|
168
|
+
value: function emit(name, data, EventPayload) {
|
160
169
|
if (this.events.has(name)) {
|
161
170
|
var eventList = this.events.get(name);
|
162
171
|
eventList.forEach(function (item) {
|
163
|
-
item.func(data,
|
172
|
+
item.func(data, EventPayload);
|
164
173
|
});
|
165
174
|
}
|
166
175
|
}
|
@@ -179,6 +188,23 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
179
188
|
this.listen(payloadContext.eventCallbackId, func);
|
180
189
|
this.dispatchToApp(payloadContext);
|
181
190
|
}
|
191
|
+
}, {
|
192
|
+
key: "queryParse",
|
193
|
+
value: function queryParse(url) {
|
194
|
+
var qs = {};
|
195
|
+
var urlString = url;
|
196
|
+
if (!urlString) {
|
197
|
+
urlString = window.location.href;
|
198
|
+
}
|
199
|
+
urlString.replace(/([^?=&#]+)(=([^&#]*))?/g, function (_$0, $1, _$2, $3) {
|
200
|
+
if ($3 === undefined) {
|
201
|
+
return '';
|
202
|
+
}
|
203
|
+
qs[$1] = decodeURIComponent($3);
|
204
|
+
return qs[$1];
|
205
|
+
});
|
206
|
+
return qs;
|
207
|
+
}
|
182
208
|
|
183
209
|
/**
|
184
210
|
* Dispatches the event payload to the app via postMessage.
|
@@ -187,20 +213,24 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
187
213
|
}, {
|
188
214
|
key: "dispatchToApp",
|
189
215
|
value: function dispatchToApp(payloadContext) {
|
190
|
-
var _this$iframes
|
216
|
+
var _this$iframes,
|
217
|
+
_this = this;
|
191
218
|
var data = {
|
192
219
|
name: MessageName.SDK_TO_APP,
|
193
220
|
context: payloadContext,
|
194
221
|
instanceId: this.instanceId
|
195
222
|
};
|
196
|
-
console.log('dispatchToApp', payloadContext);
|
197
223
|
(_this$iframes = this.iframes) === null || _this$iframes === void 0 || _this$iframes.forEach(function (iframe) {
|
198
224
|
var _iframe$origin;
|
199
225
|
if (!iframe.ref.contentWindow) {
|
200
|
-
console.
|
226
|
+
console.error('get app contentWindow error', iframe);
|
201
227
|
return;
|
202
228
|
}
|
203
|
-
|
229
|
+
var _ref = _this.queryParse(iframe.ref.src) || {},
|
230
|
+
instanceId = _ref.instanceId;
|
231
|
+
iframe.ref.contentWindow.postMessage(JSON.stringify(_objectSpread(_objectSpread({}, data), {}, {
|
232
|
+
instanceId: instanceId
|
233
|
+
})), (_iframe$origin = iframe.origin) !== null && _iframe$origin !== void 0 ? _iframe$origin : '*');
|
204
234
|
});
|
205
235
|
}
|
206
236
|
}, {
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { IoptionsParams } from "../../../types";
|
2
2
|
import { Service } from "../../index";
|
3
3
|
export declare class GlobalDataService implements Service {
|
4
4
|
private globalData;
|
5
|
-
init(initOptions:
|
5
|
+
init(initOptions: IoptionsParams, instanceId: string): void;
|
6
6
|
destroy(): void;
|
7
7
|
update(): void;
|
8
8
|
getGlobalData(dataKey: string): any;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { IoptionsParams } from '../../types';
|
2
2
|
import { PaymentContext, SDKMetaData, Service } from '../index';
|
3
3
|
/**
|
4
4
|
* @author 谦彧 <zhangmian.zm@alipay.com>
|
@@ -12,7 +12,7 @@ export declare class ServiceProvider {
|
|
12
12
|
private services;
|
13
13
|
private extendServices;
|
14
14
|
private constructor();
|
15
|
-
init(initOptions:
|
15
|
+
init(initOptions: IoptionsParams, sdkMetaData: SDKMetaData): void;
|
16
16
|
update(paymentContext: PaymentContext): void;
|
17
17
|
getService<T>(serviceName: ServiceName): T;
|
18
18
|
registerService(serviceName: string, service: Service): void;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PaymentContext, SDKMetaData, Service } from '../../index';
|
2
|
-
import {
|
2
|
+
import { IoptionsParams } from '../../../types';
|
3
3
|
import { LogExtra, LogMetaData, LogPayload } from './types';
|
4
4
|
/**
|
5
5
|
* @author 谦彧 <zhangmian.zm@alipay.com>
|
@@ -25,7 +25,7 @@ export declare class LogService implements Service {
|
|
25
25
|
private isLoaded;
|
26
26
|
private trackId;
|
27
27
|
constructor();
|
28
|
-
init(initOptions:
|
28
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
29
29
|
update(paymentContext: PaymentContext): void;
|
30
30
|
destroy(): void;
|
31
31
|
setMetaData(metaData: LogMetaData): void;
|
@@ -7,7 +7,7 @@ export type { LogPayload, LogExtra } from '../log/types';
|
|
7
7
|
export type { LogService } from '../log';
|
8
8
|
export type { Service, PaymentContext } from '../../index';
|
9
9
|
export { fomatGetwayError } from '../../../request/utils';
|
10
|
-
export type {
|
10
|
+
export type { IoptionsParams, IPaymentSessionMetaData } from '../../../types';
|
11
11
|
export { sdkVersion } from '../../../config/index';
|
12
12
|
export { appId, hostSignMap, lightSandboxMap, requestHost, sofaId, tntInstId } from '../../../config/request';
|
13
13
|
export type { RequestConfig } from '../../../types';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { IoptionsParams, PaymentContext, RequestConfig, SDKMetaData, Service } from './deps';
|
2
2
|
/**
|
3
3
|
* @author congle.zzq <congle.zzq@alipay.com>
|
4
4
|
* @date 2024/9/18
|
@@ -6,7 +6,7 @@ import { IOptionsParams, PaymentContext, RequestConfig, SDKMetaData, Service } f
|
|
6
6
|
export declare class RequesterService implements Service {
|
7
7
|
private sandboxFlag?;
|
8
8
|
private instanceId;
|
9
|
-
init(initOptions:
|
9
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
10
10
|
/**
|
11
11
|
*
|
12
12
|
* @param requestData 请求参数
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { DeviceIdParameter,
|
1
|
+
import { DeviceIdParameter, IoptionsParams } from '../../../types';
|
2
2
|
import { PaymentContext, SDKMetaData, Service } from '../../index';
|
3
3
|
import { Security } from './security';
|
4
4
|
export declare class SecurityService implements Service {
|
5
5
|
private logger;
|
6
6
|
private productScene;
|
7
7
|
static securitySdkMap: Map<string, Security>;
|
8
|
-
init(initOptions:
|
8
|
+
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
9
9
|
update(paymentContext: PaymentContext): void;
|
10
10
|
destroy(): void;
|
11
11
|
getDeviceId(deviceIdParameter?: DeviceIdParameter, isPolling?: boolean): Promise<string>;
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { RedirectBehaviorPayload } from '../index';
|
2
|
+
import { LogService } from '../service/log';
|
2
3
|
/**
|
3
4
|
* @author 谦彧 <zhangmian.zm@alipay.com>
|
4
5
|
* @date 2024/9/19
|
5
6
|
*/
|
6
7
|
export declare const redirect: (payload: RedirectBehaviorPayload, instanceId: string) => void;
|
8
|
+
/**
|
9
|
+
* 通过配置规则检测 UA 和获得回跳 scheme
|
10
|
+
*/
|
11
|
+
export declare function getBackScheme(mockUa?: string, logger?: LogService): any;
|
@@ -20,72 +20,85 @@ export var redirect = function redirect(payload, instanceId) {
|
|
20
20
|
logService.logInfo({
|
21
21
|
title: 'sdk_event_call_url_start'
|
22
22
|
}, _objectSpread({}, payload)).send();
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
// 支持 target: _blank,新开tab页打开
|
40
|
-
if (payload.browserLinkTarget === TargetEnum.BLANK) {
|
41
|
-
if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
|
42
|
-
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
43
|
-
window.open(payload.url);
|
44
|
-
return;
|
45
|
-
}
|
46
|
-
if (payload.browserLinkTarget === TargetEnum.REPLACE && !(payload !== null && payload !== void 0 && payload.applinkUrl) && !(payload !== null && payload !== void 0 && payload.schemeUrl)) {
|
47
|
-
if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
|
48
|
-
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
49
|
-
window.location.replace(payload.url);
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
if (isPC()) {
|
53
|
-
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
54
|
-
window.location.href = payload.url;
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
if (!payload.schemeUrl && !payload.applinkUrl) {
|
58
|
-
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
59
|
-
window.location.href = payload.url;
|
60
|
-
}
|
61
|
-
// Use callApp lib to evoke
|
62
|
-
// TODO replace to npm
|
63
|
-
var callAppLib = new CallApp({
|
64
|
-
successCb: function successCb(evokeAppBy) {
|
65
|
-
var type = evokeAppBy.type == 'Scheme' ? RedirectType.SchemeUrl : RedirectType.ApplinkUrl;
|
66
|
-
successCallback(payload, type, evokeAppBy.url, serviceProvider);
|
23
|
+
try {
|
24
|
+
if (payload.isCallApp && payload.schemeUrl) {
|
25
|
+
var detectSuccessDelay = payload.callAppDetectSuccessDelay;
|
26
|
+
var _callAppLib = new CallApp({
|
27
|
+
successCb: function successCb() {
|
28
|
+
successCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
|
29
|
+
},
|
30
|
+
resultJudgmentTime: detectSuccessDelay
|
31
|
+
});
|
32
|
+
_callAppLib.open({
|
33
|
+
scheme: payload.schemeUrl,
|
34
|
+
fallback: function fallback() {
|
35
|
+
failCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
return;
|
67
39
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
40
|
+
// 支持 target: _blank,新开tab页打开
|
41
|
+
if (payload.browserLinkTarget === TargetEnum.BLANK) {
|
42
|
+
if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
|
43
|
+
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
44
|
+
window.open(payload.url);
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
if (payload.browserLinkTarget === TargetEnum.REPLACE && !(payload !== null && payload !== void 0 && payload.applinkUrl) && !(payload !== null && payload !== void 0 && payload.schemeUrl)) {
|
48
|
+
if (!payload.url) return failCallback(payload, RedirectType.NormalUrl, '', serviceProvider);
|
49
|
+
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
50
|
+
window.location.replace(payload.url);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
if (isPC()) {
|
54
|
+
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
55
|
+
window.location.href = payload.url;
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
if (!payload.schemeUrl && !payload.applinkUrl) {
|
59
|
+
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
60
|
+
window.location.href = payload.url;
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
// Use callApp lib to evoke
|
64
|
+
var callAppLib = new CallApp({
|
65
|
+
successCb: function successCb(evokeAppBy) {
|
66
|
+
var type = evokeAppBy.type == 'Scheme' ? RedirectType.SchemeUrl : RedirectType.ApplinkUrl;
|
67
|
+
successCallback(payload, type, evokeAppBy.url, serviceProvider);
|
75
68
|
}
|
69
|
+
});
|
70
|
+
var callSchemeUrl = function callSchemeUrl() {
|
76
71
|
callAppLib.open({
|
77
72
|
scheme: payload.schemeUrl,
|
78
73
|
fallback: function fallback() {
|
79
|
-
|
80
|
-
if (payload.
|
81
|
-
|
74
|
+
failCallback(payload, RedirectType.SchemeUrl, payload.schemeUrl, serviceProvider);
|
75
|
+
if (payload.url) {
|
76
|
+
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
77
|
+
window.location.href = payload.url;
|
82
78
|
}
|
83
|
-
window.location.href = payload.url;
|
84
|
-
successCallback(payload, RedirectType.NormalUrl, payload.url, serviceProvider);
|
85
79
|
}
|
86
80
|
});
|
81
|
+
};
|
82
|
+
if (payload.applinkUrl) {
|
83
|
+
callAppLib.open({
|
84
|
+
link: payload.applinkUrl,
|
85
|
+
fallback: function fallback() {
|
86
|
+
failCallback(payload, RedirectType.ApplinkUrl, payload.applinkUrl, serviceProvider);
|
87
|
+
// Applink evoke failed, try to use scheme url
|
88
|
+
callSchemeUrl();
|
89
|
+
}
|
90
|
+
});
|
91
|
+
} else if (payload.schemeUrl) {
|
92
|
+
callSchemeUrl();
|
87
93
|
}
|
88
|
-
})
|
94
|
+
} catch (e) {
|
95
|
+
serviceProvider.getService('Log').logInfo({
|
96
|
+
title: 'sdk_event_call_url_failed'
|
97
|
+
}, {
|
98
|
+
redirectInfo: JSON.stringify(payload),
|
99
|
+
errorMessage: JSON.stringify(e)
|
100
|
+
}).send();
|
101
|
+
}
|
89
102
|
};
|
90
103
|
var successCallback = function successCallback(payload, type, url, serviceProvider) {
|
91
104
|
serviceProvider.getService('EventCenter').emit(EVENT.eventCallback.name, {
|
@@ -112,4 +125,138 @@ var failCallback = function failCallback(payload, type, url, serviceProvider) {
|
|
112
125
|
openType: type,
|
113
126
|
url: url
|
114
127
|
}).send();
|
115
|
-
};
|
128
|
+
};
|
129
|
+
var UA_MATCH_RULES = [{
|
130
|
+
matchRule: 'AppleWebKit\\/([0-9\\.]+).* Version\\/([0-9\\._]+) Mobile\\/([0-9\\._A-Z]+) Safari\\/([0-9\\._]+)$',
|
131
|
+
iosScheme: 'https',
|
132
|
+
andScheme: ''
|
133
|
+
}, {
|
134
|
+
matchRule: 'HeyTapBrowser',
|
135
|
+
iosScheme: '',
|
136
|
+
andScheme: ''
|
137
|
+
}, {
|
138
|
+
matchRule: 'HuaweiBrowser',
|
139
|
+
iosScheme: '',
|
140
|
+
andScheme: ''
|
141
|
+
}, {
|
142
|
+
matchRule: 'Kwai',
|
143
|
+
iosScheme: 'kwai',
|
144
|
+
andScheme: ''
|
145
|
+
}, {
|
146
|
+
matchRule: 'MQQBrowser',
|
147
|
+
iosScheme: 'mttbrowser',
|
148
|
+
andScheme: ''
|
149
|
+
}, {
|
150
|
+
matchRule: 'MicroMessenger',
|
151
|
+
iosScheme: '',
|
152
|
+
andScheme: ''
|
153
|
+
}, {
|
154
|
+
matchRule: 'MiuiBrowser',
|
155
|
+
iosScheme: '',
|
156
|
+
andScheme: ''
|
157
|
+
}, {
|
158
|
+
matchRule: 'Mozilla\\/([0-9\\.]+).* AppleWebKit\\/([0-9\\.]+).* CriOS\\/([0-9\\._]+) Mobile\\/([0-9\\._A-Z\\._a-z]+) Safari\\/([0-9\\._]+)$',
|
159
|
+
iosScheme: 'googlechrome',
|
160
|
+
andScheme: ''
|
161
|
+
}, {
|
162
|
+
matchRule: 'Mozilla\\/([0-9\\.]+).* AppleWebKit\\/([0-9\\.]+).* Version\\/([0-9\\._]+) Mobile Safari\\/([0-9\\._]+)$',
|
163
|
+
iosScheme: 'googlechrome',
|
164
|
+
andScheme: ''
|
165
|
+
}, {
|
166
|
+
matchRule: 'NewsArticle',
|
167
|
+
iosScheme: 'snssdk141',
|
168
|
+
andScheme: ''
|
169
|
+
}, {
|
170
|
+
matchRule: 'UCBrowser',
|
171
|
+
iosScheme: 'ucbrowser',
|
172
|
+
andScheme: ''
|
173
|
+
}, {
|
174
|
+
matchRule: 'VideoArticle',
|
175
|
+
iosScheme: 'snssdk32',
|
176
|
+
andScheme: ''
|
177
|
+
}, {
|
178
|
+
matchRule: 'VivoBrowser',
|
179
|
+
iosScheme: '',
|
180
|
+
andScheme: ''
|
181
|
+
}, {
|
182
|
+
matchRule: 'ZhongAnWebView',
|
183
|
+
iosScheme: 'zaapp',
|
184
|
+
andScheme: ''
|
185
|
+
}, {
|
186
|
+
matchRule: 'aweme',
|
187
|
+
iosScheme: 'snssdk1128',
|
188
|
+
andScheme: ''
|
189
|
+
}, {
|
190
|
+
matchRule: 'aweme_lite',
|
191
|
+
iosScheme: 'snssdk2329',
|
192
|
+
andScheme: ''
|
193
|
+
}, {
|
194
|
+
matchRule: 'com.xs.fm',
|
195
|
+
iosScheme: 'novelfm3040',
|
196
|
+
andScheme: ''
|
197
|
+
}, {
|
198
|
+
matchRule: 'netdisk',
|
199
|
+
iosScheme: '',
|
200
|
+
andScheme: ''
|
201
|
+
}, {
|
202
|
+
matchRule: 'qqnews',
|
203
|
+
iosScheme: 'qqnews',
|
204
|
+
andScheme: ''
|
205
|
+
}];
|
206
|
+
|
207
|
+
/**
|
208
|
+
* 通过配置规则检测 UA 和获得回跳 scheme
|
209
|
+
*/
|
210
|
+
export function getBackScheme(mockUa, logger) {
|
211
|
+
var ua = mockUa || window.navigator.userAgent || '';
|
212
|
+
// 获取规则
|
213
|
+
var uaMatchedRule = UA_MATCH_RULES;
|
214
|
+
var matchedRule;
|
215
|
+
var matched = null;
|
216
|
+
for (var i = 0; i < uaMatchedRule.length; i++) {
|
217
|
+
var rule = uaMatchedRule[i];
|
218
|
+
matched = ua.match(rule.matchRule);
|
219
|
+
if (matched) {
|
220
|
+
matchedRule = rule;
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
if (!matchedRule) {
|
225
|
+
logBackScheme(logger, ua, '');
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
if (isAndroid(ua)) {
|
229
|
+
logBackScheme(logger, ua, matchedRule.andScheme);
|
230
|
+
return matchedRule.andScheme;
|
231
|
+
}
|
232
|
+
if (isIOS(ua)) {
|
233
|
+
logBackScheme(logger, ua, matchedRule.iosScheme);
|
234
|
+
return matchedRule.iosScheme;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
function logBackScheme(logger, userAgent, scheme) {
|
238
|
+
if (logger) {
|
239
|
+
logger.logInfo({
|
240
|
+
title: 'a3753.b101271.c377460'
|
241
|
+
}, {
|
242
|
+
userAgent: userAgent,
|
243
|
+
backScheme: scheme
|
244
|
+
});
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* 当前运行环境是否 Android
|
250
|
+
*/
|
251
|
+
function isAndroid(mockUA) {
|
252
|
+
var ua = (mockUA || navigator.userAgent).toLowerCase();
|
253
|
+
return /android|adr|linux/.test(ua);
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* 当前运行环境是否 IOS
|
258
|
+
*/
|
259
|
+
function isIOS(mockUA) {
|
260
|
+
var ua = (mockUA || navigator.userAgent).toLowerCase();
|
261
|
+
return /iphone|ipad|ipod|ios|macintosh/.test(ua);
|
262
|
+
}
|