@alipay/ams-checkout 0.0.1761220900-dev.0 → 0.0.1762138227-dev.0
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 +8 -8
- package/esm/config/index.js +8 -8
- package/esm/constant/index.d.ts +4 -1
- package/esm/constant/index.js +8 -5
- package/esm/core/component/element/elementController/index.js +2 -2
- package/esm/foundation/core/index.js +43 -6
- package/esm/foundation/index.d.ts +1 -0
- package/esm/foundation/product-processor/easysafepay/index.js +4 -2
- package/esm/foundation/service/container/index.d.ts +1 -0
- package/esm/foundation/service/container/index.js +33 -2
- package/esm/loader/Proxy.js +70 -18
- package/esm/loader/index.d.ts +2 -0
- package/esm/loader/utils/common.d.ts +4 -0
- package/esm/loader/utils/common.js +10 -0
- package/esm/loader/utils/loadSDK.js +1 -1
- package/package.json +1 -1
package/esm/config/index.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ export declare const sdkVersion: string;
|
|
|
6
6
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
|
7
7
|
* TODO 这里考虑直接换成packagejson.version
|
|
8
8
|
*/
|
|
9
|
-
export declare const AMSCheckoutAppVersion = "1.
|
|
10
|
-
export declare const AMSAutoDebitAppVersion = "1.
|
|
11
|
-
export declare const AMSEasyPayAppVersion = "1.
|
|
12
|
-
export declare const AMSCashierPaymentAppVersion = "1.
|
|
13
|
-
export declare const AMSVaultingAppVersion = "1.
|
|
14
|
-
export declare const AMSPaymentElementAppVersion = "1.
|
|
15
|
-
export declare const ADDRESSElementAppVersion = "1.
|
|
16
|
-
export declare const AUTHElementAppVersion = "1.
|
|
9
|
+
export declare const AMSCheckoutAppVersion = "1.46.0";
|
|
10
|
+
export declare const AMSAutoDebitAppVersion = "1.46.0";
|
|
11
|
+
export declare const AMSEasyPayAppVersion = "1.46.0";
|
|
12
|
+
export declare const AMSCashierPaymentAppVersion = "1.46.0";
|
|
13
|
+
export declare const AMSVaultingAppVersion = "1.46.0";
|
|
14
|
+
export declare const AMSPaymentElementAppVersion = "1.46.0";
|
|
15
|
+
export declare const ADDRESSElementAppVersion = "1.46.0";
|
|
16
|
+
export declare const AUTHElementAppVersion = "1.46.0";
|
package/esm/config/index.js
CHANGED
|
@@ -36,11 +36,11 @@ export var sdkVersion = json.version;
|
|
|
36
36
|
* @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
|
|
37
37
|
* TODO 这里考虑直接换成packagejson.version
|
|
38
38
|
*/
|
|
39
|
-
export var AMSCheckoutAppVersion = '1.
|
|
40
|
-
export var AMSAutoDebitAppVersion = '1.
|
|
41
|
-
export var AMSEasyPayAppVersion = '1.
|
|
42
|
-
export var AMSCashierPaymentAppVersion = '1.
|
|
43
|
-
export var AMSVaultingAppVersion = '1.
|
|
44
|
-
export var AMSPaymentElementAppVersion = '1.
|
|
45
|
-
export var ADDRESSElementAppVersion = '1.
|
|
46
|
-
export var AUTHElementAppVersion = '1.
|
|
39
|
+
export var AMSCheckoutAppVersion = '1.46.0'; // 兜底版本号
|
|
40
|
+
export var AMSAutoDebitAppVersion = '1.46.0'; // 代扣
|
|
41
|
+
export var AMSEasyPayAppVersion = '1.46.0'; // easypay
|
|
42
|
+
export var AMSCashierPaymentAppVersion = '1.46.0'; // 收银台(卡、apm)
|
|
43
|
+
export var AMSVaultingAppVersion = '1.46.0'; // 绑卡
|
|
44
|
+
export var AMSPaymentElementAppVersion = '1.46.0'; // payment element
|
|
45
|
+
export var ADDRESSElementAppVersion = '1.46.0'; // address element
|
|
46
|
+
export var AUTHElementAppVersion = '1.46.0'; // auth element
|
package/esm/constant/index.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export declare const ERRORMESSAGE: {
|
|
|
98
98
|
code: string;
|
|
99
99
|
message: string;
|
|
100
100
|
};
|
|
101
|
-
|
|
101
|
+
INITIALIZE_TIMEOUT: {
|
|
102
102
|
code: string;
|
|
103
103
|
API: {
|
|
104
104
|
code: string;
|
|
@@ -288,6 +288,9 @@ export declare const EVENT: {
|
|
|
288
288
|
forwardName: string;
|
|
289
289
|
uniqueKey: string;
|
|
290
290
|
};
|
|
291
|
+
canIUse: {
|
|
292
|
+
name: string;
|
|
293
|
+
};
|
|
291
294
|
};
|
|
292
295
|
export declare const SENDEVENT: {
|
|
293
296
|
validateFields: {
|
package/esm/constant/index.js
CHANGED
|
@@ -98,14 +98,14 @@ export var ERRORMESSAGE = {
|
|
|
98
98
|
code: 'UI_STATE_ERROR',
|
|
99
99
|
message: 'An error occurred. The transaction cannot be initiated.'
|
|
100
100
|
},
|
|
101
|
-
|
|
102
|
-
code: '
|
|
101
|
+
INITIALIZE_TIMEOUT: {
|
|
102
|
+
code: 'INITIALIZE_TIMEOUT',
|
|
103
103
|
API: {
|
|
104
|
-
code: '
|
|
104
|
+
code: 'INITIALIZE_API_TIMEOUT',
|
|
105
105
|
message: 'An error occurred. The transaction cannot be initiated.'
|
|
106
106
|
},
|
|
107
107
|
WEB: {
|
|
108
|
-
code: '
|
|
108
|
+
code: 'INITIALIZE_WEB_TIMEOUT',
|
|
109
109
|
message: 'An error occurred; the transaction cannot be initiated.'
|
|
110
110
|
}
|
|
111
111
|
},
|
|
@@ -287,12 +287,15 @@ export var EVENT = {
|
|
|
287
287
|
},
|
|
288
288
|
// Element支付完成后事件
|
|
289
289
|
submitPromiseCallback: {
|
|
290
|
-
name: '
|
|
290
|
+
name: 'onSubmitPayCallback'
|
|
291
291
|
},
|
|
292
292
|
validateFieldsResult: {
|
|
293
293
|
name: 'validateFieldsResult',
|
|
294
294
|
forwardName: 'validateFieldsResultForward',
|
|
295
295
|
uniqueKey: 'uservalidateFieldsResult'
|
|
296
|
+
},
|
|
297
|
+
canIUse: {
|
|
298
|
+
name: 'canIUse'
|
|
296
299
|
}
|
|
297
300
|
};
|
|
298
301
|
|
|
@@ -195,7 +195,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
195
195
|
title: 'sdk_event_web_app_timeout'
|
|
196
196
|
});
|
|
197
197
|
resolve({
|
|
198
|
-
error: ERRORMESSAGE.
|
|
198
|
+
error: ERRORMESSAGE.INITIALIZE_TIMEOUT.WEB
|
|
199
199
|
});
|
|
200
200
|
}, TIMEOUT_DURATION);
|
|
201
201
|
}
|
|
@@ -642,7 +642,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
642
642
|
_context5.t0 = _context5["catch"](1);
|
|
643
643
|
this.handleInitializationError();
|
|
644
644
|
readyCallback({
|
|
645
|
-
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.
|
|
645
|
+
error: _objectSpread(_objectSpread({}, ERRORMESSAGE.INITIALIZE_TIMEOUT.API), {}, {
|
|
646
646
|
traceId: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.traceId
|
|
647
647
|
})
|
|
648
648
|
});
|
|
@@ -22,6 +22,7 @@ import { getGrayscaleId } from "../utils/gray_scale_utils";
|
|
|
22
22
|
import { convertPaymentSession, getWebAppVersion, saveWebAppVersion } from "../utils/payment_context_utils";
|
|
23
23
|
import { redirect } from "../utils/redirect_utils";
|
|
24
24
|
import { parseWebAppMatchConfig } from "../utils/web_app_url_utils";
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* @author 谦彧 <zhangmian.zm@alipay.com>
|
|
27
28
|
* @date 2024/9/17
|
|
@@ -231,6 +232,32 @@ export var AntomSDKCore = /*#__PURE__*/function () {
|
|
|
231
232
|
_this.eventLogging = data.popWindowEventInfo.eventLogging;
|
|
232
233
|
}
|
|
233
234
|
});
|
|
235
|
+
eventCenter.listen(EVENT.canIUse.name, function (data, payload) {
|
|
236
|
+
var _payload$context5;
|
|
237
|
+
// 前置校验
|
|
238
|
+
var funcName = data === null || data === void 0 ? void 0 : data.funcName;
|
|
239
|
+
if (!funcName || typeof funcName !== 'string') {
|
|
240
|
+
var _payload$context4;
|
|
241
|
+
eventCenter.dispatchToApp({
|
|
242
|
+
event: 'appEventCallback',
|
|
243
|
+
eventCallbackId: (_payload$context4 = payload.context) === null || _payload$context4 === void 0 ? void 0 : _payload$context4.eventCallbackId,
|
|
244
|
+
data: {
|
|
245
|
+
exist: false,
|
|
246
|
+
success: false
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
var exist = eventCenter.isExist(funcName);
|
|
252
|
+
eventCenter.dispatchToApp({
|
|
253
|
+
event: 'appEventCallback',
|
|
254
|
+
eventCallbackId: (_payload$context5 = payload.context) === null || _payload$context5 === void 0 ? void 0 : _payload$context5.eventCallbackId,
|
|
255
|
+
data: {
|
|
256
|
+
exist: exist,
|
|
257
|
+
success: true
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
234
261
|
|
|
235
262
|
// execute additional logic from specified product
|
|
236
263
|
if (this.productProcessors[sdkMetaData.productScene]) {
|
|
@@ -242,7 +269,7 @@ export var AntomSDKCore = /*#__PURE__*/function () {
|
|
|
242
269
|
value: function () {
|
|
243
270
|
var _startBizFlow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options) {
|
|
244
271
|
var _this$paymentContext$, _this$paymentContext$2, _this$paymentContext$3;
|
|
245
|
-
var paymentSession, displayInfo, _convertPaymentSessio2, paymentSessionId, paymentSessionMetaData, mid, webAppMatchConfig, webAppVersion, productScene, paymentMethod, _this$bizFlowStartBeh, payload, eventCenter, data;
|
|
272
|
+
var paymentSession, displayInfo, _convertPaymentSessio2, paymentSessionId, paymentSessionMetaData, mid, webAppMatchConfig, webAppVersion, productScene, paymentMethod, _this$bizFlowStartBeh, payload, eventCenter, data, normalUrl;
|
|
246
273
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
247
274
|
while (1) switch (_context4.prev = _context4.next) {
|
|
248
275
|
case 0:
|
|
@@ -323,14 +350,18 @@ export var AntomSDKCore = /*#__PURE__*/function () {
|
|
|
323
350
|
return _context4.abrupt("return");
|
|
324
351
|
case 36:
|
|
325
352
|
if (!(this.bizFlowStartBehavior.behaviorType === 'REDIRECT')) {
|
|
326
|
-
_context4.next =
|
|
353
|
+
_context4.next = 49;
|
|
327
354
|
break;
|
|
328
355
|
}
|
|
329
356
|
payload = (_this$bizFlowStartBeh = this.bizFlowStartBehavior) === null || _this$bizFlowStartBeh === void 0 ? void 0 : _this$bizFlowStartBeh.payload;
|
|
330
|
-
|
|
331
|
-
|
|
357
|
+
console.log('sdk 打印', payload);
|
|
358
|
+
console.log('sdk 触发', options);
|
|
359
|
+
//Sessiondata中authUrlInfo的openInApp为true,说明端内打开,不需要处理isNativeAppWebview的外跳事件逻辑
|
|
360
|
+
if (!(options.isNativeAppWebview && !!!payload.openInApp)) {
|
|
361
|
+
_context4.next = 46;
|
|
332
362
|
break;
|
|
333
363
|
}
|
|
364
|
+
console.log('sdk 打印跳转', options);
|
|
334
365
|
eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
|
|
335
366
|
data = {
|
|
336
367
|
normalUrl: (payload === null || payload === void 0 ? void 0 : payload.url) || '',
|
|
@@ -344,10 +375,16 @@ export var AntomSDKCore = /*#__PURE__*/function () {
|
|
|
344
375
|
}
|
|
345
376
|
});
|
|
346
377
|
return _context4.abrupt("return");
|
|
347
|
-
case
|
|
378
|
+
case 46:
|
|
379
|
+
if (payload.url && payload.openInApp && options.isNativeAppWebview) {
|
|
380
|
+
//Sessiondata中authUrlInfo的openInApp为true,normalUrl存在,isNativeAppWebview为true,拼接source=embedded
|
|
381
|
+
normalUrl = new URL(payload.url);
|
|
382
|
+
normalUrl.searchParams.set('source', 'embedded');
|
|
383
|
+
payload.url = normalUrl.toString();
|
|
384
|
+
}
|
|
348
385
|
redirect(payload, this.instanceId);
|
|
349
386
|
return _context4.abrupt("return");
|
|
350
|
-
case
|
|
387
|
+
case 49:
|
|
351
388
|
case "end":
|
|
352
389
|
return _context4.stop();
|
|
353
390
|
}
|
|
@@ -62,6 +62,7 @@ export interface RedirectBehaviorPayload {
|
|
|
62
62
|
browserLinkTarget?: TargetEnum;
|
|
63
63
|
isCallApp?: boolean;
|
|
64
64
|
callAppDetectSuccessDelay?: number;
|
|
65
|
+
openInApp?: boolean;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Provide some capability, such as MonitorService, EventBusService, SecurityService
|
|
@@ -153,13 +153,15 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
|
|
|
153
153
|
data = {
|
|
154
154
|
url: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl,
|
|
155
155
|
schemeUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl,
|
|
156
|
-
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl
|
|
156
|
+
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.authUrl,
|
|
157
|
+
openInApp: (authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.openInApp) || false
|
|
157
158
|
};
|
|
158
159
|
} else {
|
|
159
160
|
data = {
|
|
160
161
|
url: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.normalUrl,
|
|
161
162
|
schemeUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.schemeUrl,
|
|
162
|
-
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.applinkUrl
|
|
163
|
+
applinkUrl: authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.applinkUrl,
|
|
164
|
+
openInApp: (authUrlInfo === null || authUrlInfo === void 0 ? void 0 : authUrlInfo.openInApp) || false
|
|
163
165
|
};
|
|
164
166
|
}
|
|
165
167
|
var result = {
|
|
@@ -7,12 +7,12 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
7
7
|
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; }
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
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); }
|
|
10
|
-
import { isEmpty } from "../../../util";
|
|
11
10
|
import { addInlineLoading, createInlineBaseElement } from "../../../component/component.inline.style";
|
|
12
11
|
import { addPopupLoading, createBaseElement } from "../../../component/component.popup.style";
|
|
13
12
|
import { insertStyleSheet } from "../../../component/popupWindow.style";
|
|
14
|
-
import { COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CLOSE_MASK_BLOCK_ID, COMPONENT_CONTAINER_ID, ERRORMESSAGE, EVENT, LOADING_ID, MOCKUP_ID, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT
|
|
13
|
+
import { closeImg, closeImgLight, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CLOSE_MASK_BLOCK_ID, COMPONENT_CONTAINER_ID, ERRORMESSAGE, EVENT, LOADING_ID, MOCKUP_ID, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../../constant";
|
|
15
14
|
import { DisplayTypeEnum, ProductSceneEnum } from "../../../types";
|
|
15
|
+
import { isEmpty } from "../../../util";
|
|
16
16
|
import { ServiceProvider } from "../index";
|
|
17
17
|
import { PopupManager } from "./popup";
|
|
18
18
|
import { createIframe, startSizeChangeAnim } from "./utils";
|
|
@@ -217,6 +217,9 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
|
217
217
|
this.eventCenter.listen(EVENT.appHeartBeat.name, function () {
|
|
218
218
|
_this.handleAppHeartBeat();
|
|
219
219
|
});
|
|
220
|
+
this.eventCenter.listen(EVENT.canIUse.name, function (data, payload) {
|
|
221
|
+
_this.handleCanIUse(data, payload);
|
|
222
|
+
});
|
|
220
223
|
/**
|
|
221
224
|
* 目前仅用于ESP V2的 web sdk
|
|
222
225
|
* 原因: 在账户输入页和OTP页面的h5场景下键盘弹起页面会有问题,iframe有固定高度,键盘弹起时应用层不会触发大小变化
|
|
@@ -446,6 +449,34 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
|
446
449
|
data: data
|
|
447
450
|
});
|
|
448
451
|
}
|
|
452
|
+
}, {
|
|
453
|
+
key: "handleCanIUse",
|
|
454
|
+
value: function handleCanIUse(data, payload) {
|
|
455
|
+
var _payload$context3;
|
|
456
|
+
// 前置校验
|
|
457
|
+
var funcName = data === null || data === void 0 ? void 0 : data.funcName;
|
|
458
|
+
if (!funcName || typeof funcName !== 'string') {
|
|
459
|
+
var _payload$context2;
|
|
460
|
+
this.eventCenter.dispatchToApp({
|
|
461
|
+
event: 'appEventCallback',
|
|
462
|
+
eventCallbackId: (_payload$context2 = payload.context) === null || _payload$context2 === void 0 ? void 0 : _payload$context2.eventCallbackId,
|
|
463
|
+
data: {
|
|
464
|
+
exist: false,
|
|
465
|
+
success: false
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
var exist = this.eventCenter.isExist(funcName);
|
|
471
|
+
this.eventCenter.dispatchToApp({
|
|
472
|
+
event: 'appEventCallback',
|
|
473
|
+
eventCallbackId: (_payload$context3 = payload.context) === null || _payload$context3 === void 0 ? void 0 : _payload$context3.eventCallbackId,
|
|
474
|
+
data: {
|
|
475
|
+
exist: exist,
|
|
476
|
+
success: true
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
449
480
|
}, {
|
|
450
481
|
key: "getWebApp",
|
|
451
482
|
value: function getWebApp() {
|
package/esm/loader/Proxy.js
CHANGED
|
@@ -16,10 +16,10 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
16
16
|
* **/
|
|
17
17
|
import ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';
|
|
18
18
|
import { instanceApiMap } from "./constant";
|
|
19
|
-
import { supportsProxy } from "./utils/common";
|
|
19
|
+
import { supportsDefineProperty, supportsProxy } from "./utils/common";
|
|
20
20
|
import { setDebugContext } from "./utils/debugger";
|
|
21
21
|
import { loadSdk, newActualInstance } from "./utils/loadSDK";
|
|
22
|
-
import { logger } from "./utils/logger";
|
|
22
|
+
import { consoleLogger, logger } from "./utils/logger";
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line
|
|
25
25
|
|
|
@@ -111,6 +111,18 @@ export function createBaseProxy(constructorName) {
|
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
};
|
|
114
|
+
|
|
115
|
+
/***构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象*/
|
|
116
|
+
var _newInstanceForError = function _newInstanceForError(errorObj) {
|
|
117
|
+
var instanceForError = {};
|
|
118
|
+
var needCapturedApis = instanceApiMap[constructorName];
|
|
119
|
+
needCapturedApis.forEach(function (api) {
|
|
120
|
+
instanceForError[api] = function () {
|
|
121
|
+
return Promise.resolve(errorObj);
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
return instanceForError;
|
|
125
|
+
};
|
|
114
126
|
var BaseProxy = /*#__PURE__*/function () {
|
|
115
127
|
// 返回代理实例对象
|
|
116
128
|
function BaseProxy(newProps, debugProps) {
|
|
@@ -140,33 +152,62 @@ export function createBaseProxy(constructorName) {
|
|
|
140
152
|
value: function loadSDKAndCreateInstance(constructorName, newProps) {
|
|
141
153
|
var _this = this;
|
|
142
154
|
loadSdk().then(function () {
|
|
143
|
-
var actualInstance = newActualInstance(constructorName, newProps);
|
|
144
|
-
|
|
145
|
-
// 从newProxy到初始化真实sdk实例花费时间
|
|
146
|
-
//TODO 最好尝试发送给web应用层进行上报
|
|
147
|
-
logger.logInfo({
|
|
148
|
-
title: 'report_customized_performance_m5'
|
|
149
|
-
}, {
|
|
150
|
-
m5: Date.now() - _this.startTime
|
|
151
|
-
});
|
|
152
|
-
logger.logInfo({
|
|
153
|
-
title: 'create_actual_instance_success'
|
|
154
|
-
}, {
|
|
155
|
-
constructorName: constructorName
|
|
156
|
-
});
|
|
157
155
|
try {
|
|
156
|
+
var actualInstance = newActualInstance(constructorName, newProps);
|
|
157
|
+
// 从newProxy到初始化真实sdk实例花费时间
|
|
158
|
+
logger.logInfo({
|
|
159
|
+
title: 'report_customized_performance_m5'
|
|
160
|
+
}, {
|
|
161
|
+
m5: Date.now() - _this.startTime
|
|
162
|
+
});
|
|
163
|
+
logger.logInfo({
|
|
164
|
+
title: 'create_actual_instance_success'
|
|
165
|
+
}, {
|
|
166
|
+
constructorName: constructorName
|
|
167
|
+
});
|
|
168
|
+
consoleLogger.log('create_actual_instance_success');
|
|
158
169
|
_this.actualInstance = actualInstance;
|
|
159
170
|
_this.hasActualInstance = true;
|
|
160
171
|
_this.executePendingCalls();
|
|
161
172
|
} catch (error) {
|
|
173
|
+
//创建实例失败时,构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
|
|
174
|
+
var instanceForError = _newInstanceForError({
|
|
175
|
+
error: {
|
|
176
|
+
code: 'INTERNAL_ERROR',
|
|
177
|
+
message: 'create_actual_instance_error'
|
|
178
|
+
},
|
|
179
|
+
status: 'FAIL'
|
|
180
|
+
});
|
|
181
|
+
_this.actualInstance = instanceForError;
|
|
182
|
+
_this.hasActualInstance = true;
|
|
183
|
+
_this.executePendingCalls();
|
|
162
184
|
logger.logError({
|
|
163
185
|
title: 'create_actual_instance_error'
|
|
164
186
|
}, {
|
|
165
187
|
errorMessage: error,
|
|
166
188
|
constructorName: constructorName
|
|
167
189
|
});
|
|
168
|
-
|
|
190
|
+
consoleLogger.error('create_actual_instance_error');
|
|
169
191
|
}
|
|
192
|
+
}).catch(function (error) {
|
|
193
|
+
//SDK加载失败时,构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
|
|
194
|
+
var instanceForError = _newInstanceForError({
|
|
195
|
+
error: {
|
|
196
|
+
code: 'INITIALIZE_WEB_TIMEOUT',
|
|
197
|
+
message: 'load_sdk_resource_error'
|
|
198
|
+
},
|
|
199
|
+
status: 'FAIL'
|
|
200
|
+
});
|
|
201
|
+
_this.actualInstance = instanceForError;
|
|
202
|
+
_this.hasActualInstance = true;
|
|
203
|
+
_this.executePendingCalls();
|
|
204
|
+
logger.logError({
|
|
205
|
+
title: 'load_sdk_resource_error'
|
|
206
|
+
}, {
|
|
207
|
+
errorMessage: error,
|
|
208
|
+
constructorName: constructorName
|
|
209
|
+
});
|
|
210
|
+
consoleLogger.error('load_sdk_resource_error');
|
|
170
211
|
});
|
|
171
212
|
}
|
|
172
213
|
|
|
@@ -174,13 +215,22 @@ export function createBaseProxy(constructorName) {
|
|
|
174
215
|
}, {
|
|
175
216
|
key: "newProxyInstance",
|
|
176
217
|
value: function newProxyInstance() {
|
|
218
|
+
// 检测浏览器API兼容性
|
|
219
|
+
var isProxySupports = supportsProxy();
|
|
220
|
+
var isDefinePropertySupports = supportsDefineProperty();
|
|
221
|
+
if (!isProxySupports && !isDefinePropertySupports) {
|
|
222
|
+
logger.logError({
|
|
223
|
+
title: 'create_proxy_instance_error'
|
|
224
|
+
});
|
|
225
|
+
consoleLogger.error('The browser does not support either Proxy or Object.defineProperty.');
|
|
226
|
+
}
|
|
177
227
|
try {
|
|
178
228
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
179
229
|
var self = this;
|
|
180
230
|
|
|
181
231
|
// 如果浏览器不支持Proxy,则使用Polyfill降级 https://github.com/GoogleChrome/proxy-polyfill,
|
|
182
232
|
// 注意: Polyfill降级方案需要预先定义需要捕获的api。
|
|
183
|
-
if (
|
|
233
|
+
if (isProxySupports) {
|
|
184
234
|
return _newProxyInstance(self);
|
|
185
235
|
} else {
|
|
186
236
|
logger.logInfo({
|
|
@@ -195,6 +245,7 @@ export function createBaseProxy(constructorName) {
|
|
|
195
245
|
errorMessage: e,
|
|
196
246
|
constructorName: constructorName
|
|
197
247
|
});
|
|
248
|
+
consoleLogger.error('The browser does not support either Proxy or Object.defineProperty.');
|
|
198
249
|
}
|
|
199
250
|
}
|
|
200
251
|
|
|
@@ -213,6 +264,7 @@ export function createBaseProxy(constructorName) {
|
|
|
213
264
|
try {
|
|
214
265
|
var _this$actualInstance;
|
|
215
266
|
var result = (_this$actualInstance = this.actualInstance)[method].apply(_this$actualInstance, _toConsumableArray(args));
|
|
267
|
+
consoleLogger.log("call API [".concat(constructorName, ".").concat(method, "]"));
|
|
216
268
|
resolve(result);
|
|
217
269
|
} catch (error) {
|
|
218
270
|
logger.logError({
|
package/esm/loader/index.d.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { AMSCashierPayment, AMSEasyPay, AMSElement } from '../main';
|
|
9
9
|
interface AMSCashierPaymentWrapper extends AMSCashierPayment {
|
|
10
|
+
preload: typeof AMSCashierPayment.preload;
|
|
10
11
|
}
|
|
11
12
|
interface AMSEasyPayWrapper extends AMSEasyPay {
|
|
13
|
+
preload: typeof AMSCashierPayment.preload;
|
|
12
14
|
}
|
|
13
15
|
interface AMSElementWrapper extends AMSElement {
|
|
14
16
|
}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* 检测浏览器是否兼容Proxy对象
|
|
3
3
|
*/
|
|
4
4
|
export declare function supportsProxy(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* 检测浏览器是否兼容defineProperty
|
|
7
|
+
*/
|
|
8
|
+
export declare function supportsDefineProperty(): boolean;
|
|
5
9
|
/**
|
|
6
10
|
* @description 尝试调用window.tracker上报m5性能数据
|
|
7
11
|
* @param options 自定义性能埋点 m1-m20, m1-资源加载耗时,m2-首屏数据请求耗时,m3-首屏数据请求完成耗时,m4-首屏渲染完成耗时
|
|
@@ -24,6 +24,16 @@ export function supportsProxy() {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 检测浏览器是否兼容defineProperty
|
|
29
|
+
*/
|
|
30
|
+
export function supportsDefineProperty() {
|
|
31
|
+
if (typeof Object.defineProperty !== 'function') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
/**
|
|
28
38
|
* @description 尝试调用window.tracker上报m5性能数据
|
|
29
39
|
* @param options 自定义性能埋点 m1-m20, m1-资源加载耗时,m2-首屏数据请求耗时,m3-首屏数据请求完成耗时,m4-首屏渲染完成耗时
|
|
@@ -35,7 +35,7 @@ export function loadSdk() {
|
|
|
35
35
|
// 定义onload和onerror事件
|
|
36
36
|
script.onload = function () {
|
|
37
37
|
consoleLogger.log("Load SDK Success , SDK URL: ".concat(sdkSrc));
|
|
38
|
-
resolve(
|
|
38
|
+
resolve(true);
|
|
39
39
|
};
|
|
40
40
|
script.onerror = function () {
|
|
41
41
|
consoleLogger.log("Failed to load SDK: ".concat(sdkSrc));
|