@alipay/ams-checkout 0.0.1761220900-dev.0 → 0.0.1761220900-dev.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.
@@ -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: {
@@ -293,6 +293,9 @@ export var EVENT = {
293
293
  name: 'validateFieldsResult',
294
294
  forwardName: 'validateFieldsResultForward',
295
295
  uniqueKey: 'uservalidateFieldsResult'
296
+ },
297
+ canIUse: {
298
+ name: 'canIUse'
296
299
  }
297
300
  };
298
301
 
@@ -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]) {
@@ -37,5 +37,6 @@ export declare class ContainerService implements Service {
37
37
  private handleCloseButtonTheme;
38
38
  private handlePopupWindow;
39
39
  private handlePopWindow;
40
+ private handleCanIUse;
40
41
  getWebApp(): HTMLIFrameElement;
41
42
  }
@@ -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, closeImg, closeImgLight } from "../../../constant";
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() {
@@ -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
- _this.rejectPendingCalls(error);
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 (supportsProxy()) {
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({
@@ -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(false);
38
+ resolve(true);
39
39
  };
40
40
  script.onerror = function () {
41
41
  consoleLogger.log("Failed to load SDK: ".concat(sdkSrc));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1761220900-dev.0",
3
+ "version": "0.0.1761220900-dev.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",