@alipay/ams-checkout 0.0.1762138227-dev.0 → 0.0.1762138227-dev.10

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.
@@ -15,11 +15,12 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
15
15
  * Proxy代理层
16
16
  * **/
17
17
  import ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';
18
- import { instanceApiMap } from "./constant";
18
+ import { EConstructorName, instanceApiMap } from "./constant";
19
19
  import { supportsDefineProperty, supportsProxy } from "./utils/common";
20
20
  import { setDebugContext } from "./utils/debugger";
21
21
  import { loadSdk, newActualInstance } from "./utils/loadSDK";
22
22
  import { consoleLogger, logger } from "./utils/logger";
23
+ import { setProxyEndTime, setProxyStartTime } from "./utils/proxyPerformance";
23
24
 
24
25
  // eslint-disable-next-line
25
26
 
@@ -49,6 +50,7 @@ export function createBaseProxy(constructorName) {
49
50
  } else {
50
51
  // SDK未加载,记录调用
51
52
  return new Promise(function (resolve, reject) {
53
+ consoleLogger.log("Cache API [".concat(constructorName, ".").concat(prop, "]"));
52
54
  self.pendingCalls.push({
53
55
  method: prop,
54
56
  args: args,
@@ -88,6 +90,7 @@ export function createBaseProxy(constructorName) {
88
90
  } else {
89
91
  // SDK未加载,记录调用
90
92
  return new Promise(function (resolve, reject) {
93
+ consoleLogger.log("Cache API [".concat(constructorName, ".").concat(prop, "]"));
91
94
  self.pendingCalls.push({
92
95
  method: prop,
93
96
  args: args,
@@ -125,21 +128,64 @@ export function createBaseProxy(constructorName) {
125
128
  };
126
129
  var BaseProxy = /*#__PURE__*/function () {
127
130
  // 返回代理实例对象
128
- function BaseProxy(newProps, debugProps) {
131
+ function BaseProxy(_newProps, debugProps) {
132
+ var _this = this;
129
133
  _classCallCheck(this, BaseProxy);
130
134
  _defineProperty(this, "hasActualInstance", false);
131
135
  _defineProperty(this, "pendingCalls", []);
132
136
  _defineProperty(this, "actualInstance", null);
133
137
  _defineProperty(this, "proxyInstance", null);
134
138
  _defineProperty(this, "startTime", 0);
139
+ _defineProperty(this, "onCreateInstanceError", function (newProps) {
140
+ // 不同实例进行不同的错误处理方案
141
+ if (constructorName === EConstructorName.AMSElement) {
142
+ _this.throwErrorWithPromise({
143
+ error: {
144
+ code: 'UI_STATE_ERROR',
145
+ message: 'create_actual_instance_error'
146
+ }
147
+ });
148
+ } else if (constructorName === EConstructorName.AMSEasyPay) {
149
+ _this.throwErrorWithOnEventCallback({
150
+ code: 'SDK_INTERNAL_ERROR',
151
+ message: 'create_actual_instance_error'
152
+ }, newProps);
153
+ } else {
154
+ _this.throwErrorWithOnEventCallback({
155
+ code: 'SDK_INTERNAL_ERROR',
156
+ message: 'create_actual_instance_error'
157
+ }, newProps);
158
+ }
159
+ });
160
+ _defineProperty(this, "onLoadSDKError", function (newProps) {
161
+ if (constructorName === EConstructorName.AMSElement) {
162
+ _this.throwErrorWithPromise({
163
+ error: {
164
+ code: 'INITIALIZE_WEB_TIMEOUT',
165
+ message: 'load_sdk_resource_error'
166
+ }
167
+ });
168
+ } else if (constructorName === EConstructorName.AMSEasyPay) {
169
+ _this.throwErrorWithOnEventCallback({
170
+ code: 'SDK_INTERNAL_ERROR',
171
+ message: 'load_sdk_resource_error'
172
+ }, newProps);
173
+ } else {
174
+ _this.throwErrorWithOnEventCallback({
175
+ code: 'SDK_INTERNAL_ERROR',
176
+ message: 'load_sdk_resource_error'
177
+ }, newProps);
178
+ }
179
+ });
135
180
  this.startTime = Date.now();
136
-
137
181
  // 初始化debug参数
138
182
  setDebugContext(debugProps);
183
+ // 记录开始时间
184
+ setProxyStartTime(constructorName, this.startTime);
139
185
  // 创建代理实例
140
186
  this.proxyInstance = this.newProxyInstance();
141
187
  // 加载sdk并创建真实实例
142
- this.loadSDKAndCreateInstance(constructorName, newProps);
188
+ this.loadSDKAndCreateInstance(constructorName, _newProps);
143
189
  logger.logInfo({
144
190
  title: 'create_proxy_instance_success'
145
191
  });
@@ -150,64 +196,49 @@ export function createBaseProxy(constructorName) {
150
196
  _createClass(BaseProxy, [{
151
197
  key: "loadSDKAndCreateInstance",
152
198
  value: function loadSDKAndCreateInstance(constructorName, newProps) {
153
- var _this = this;
154
- loadSdk().then(function () {
199
+ var _this2 = this;
200
+ loadSdk().then(function (_ref) {
201
+ var loadType = _ref.loadType;
155
202
  try {
156
203
  var actualInstance = newActualInstance(constructorName, newProps);
157
- // 从newProxy到初始化真实sdk实例花费时间
204
+ var newActualInstanceDuration = Date.now() - _this2.startTime;
205
+ // 记录结束时间
206
+ setProxyEndTime(constructorName, Date.now());
207
+ // 上报newProxy到初始化真实sdk实例花费时间,忽略SDK缓存场景
158
208
  logger.logInfo({
159
- title: 'report_customized_performance_m5'
209
+ title: 'loadSDK_and_create_actual_instance'
160
210
  }, {
161
- m5: Date.now() - _this.startTime
211
+ constructorName: constructorName,
212
+ loadDuration: loadType === 'network' ? newActualInstanceDuration : undefined
162
213
  });
214
+ // 热更新全流程成功率监控
163
215
  logger.logInfo({
164
- title: 'create_actual_instance_success'
216
+ title: 'create_antom_instance'
165
217
  }, {
166
- constructorName: constructorName
218
+ constructorName: constructorName,
219
+ result: 'Y'
167
220
  });
168
221
  consoleLogger.log('create_actual_instance_success');
169
- _this.actualInstance = actualInstance;
170
- _this.hasActualInstance = true;
171
- _this.executePendingCalls();
222
+ _this2.actualInstance = actualInstance;
223
+ _this2.hasActualInstance = true;
224
+ _this2.executePendingCalls();
172
225
  } 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();
184
- logger.logError({
185
- title: 'create_actual_instance_error'
226
+ logger.logInfo({
227
+ title: 'create_antom_instance'
186
228
  }, {
187
- errorMessage: error,
188
- constructorName: constructorName
229
+ constructorName: constructorName,
230
+ result: 'N'
189
231
  });
190
- consoleLogger.error('create_actual_instance_error');
232
+ _this2.onCreateInstanceError(newProps);
191
233
  }
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'
234
+ }).catch(function () {
235
+ logger.logInfo({
236
+ title: 'create_antom_instance'
206
237
  }, {
207
- errorMessage: error,
208
- constructorName: constructorName
238
+ constructorName: constructorName,
239
+ result: 'N'
209
240
  });
210
- consoleLogger.error('load_sdk_resource_error');
241
+ _this2.onLoadSDKError(newProps);
211
242
  });
212
243
  }
213
244
 
@@ -289,6 +320,43 @@ export function createBaseProxy(constructorName) {
289
320
  reject(error);
290
321
  }
291
322
  }
323
+ }, {
324
+ key: "throwErrorWithPromise",
325
+ value:
326
+ // 使用Promise.then来抛出错误对象 构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
327
+ function throwErrorWithPromise(errorObj) {
328
+ var _errorObj$error;
329
+ var message = errorObj === null || errorObj === void 0 || (_errorObj$error = errorObj.error) === null || _errorObj$error === void 0 ? void 0 : _errorObj$error.message;
330
+ var instanceForError = _newInstanceForError(errorObj);
331
+ this.actualInstance = instanceForError;
332
+ this.hasActualInstance = true;
333
+ this.executePendingCalls();
334
+ logger.logError({
335
+ title: message
336
+ }, {
337
+ errorMessage: message,
338
+ constructorName: constructorName
339
+ });
340
+ consoleLogger.error(message);
341
+ }
342
+
343
+ // 使用onEventCallback向外抛出SDK内部错误
344
+ }, {
345
+ key: "throwErrorWithOnEventCallback",
346
+ value: function throwErrorWithOnEventCallback(errorObj, newProps) {
347
+ var onEventCallbackFn = newProps === null || newProps === void 0 ? void 0 : newProps.onEventCallback;
348
+ var message = errorObj.message;
349
+ if (typeof onEventCallbackFn === 'function') {
350
+ onEventCallbackFn === null || onEventCallbackFn === void 0 || onEventCallbackFn.call(null, errorObj);
351
+ }
352
+ logger.logError({
353
+ title: message
354
+ }, {
355
+ errorMessage: message,
356
+ constructorName: constructorName
357
+ });
358
+ consoleLogger.error(message);
359
+ }
292
360
  }]);
293
361
  return BaseProxy;
294
362
  }();
@@ -27,6 +27,9 @@ export declare const instanceApiMap: Record<EConstructorName, string[]>;
27
27
  * SDK 集成类型枚举
28
28
  */
29
29
  export type AntomWebSDKIntegrationType = 'CDN' | 'NPM';
30
+ /**
31
+ * SDK 地址
32
+ */
30
33
  export declare const SDK_URL: {
31
34
  DEV: string;
32
35
  PROD: string;
@@ -27,9 +27,10 @@ export var instanceApiMap = _defineProperty(_defineProperty(_defineProperty({},
27
27
  * SDK 集成类型枚举
28
28
  */
29
29
 
30
- // TODO SDK 地址
30
+ /**
31
+ * SDK 地址
32
+ */
31
33
  export var SDK_URL = {
32
- DEV: 'https://sdk-dev.marmot-cloud.com/package/ams-checkout/dev-1753362745/dist/umd/ams-checkout.min.js',
33
- // marmot测试用sdk地址 待正式上线前替换
34
- PROD: 'https://er-test.marmot-cloud.com/1.0.0/dist/umd/ams-checkout.min.js'
34
+ DEV: 'http://js-dev.antom.com/v2/ams-checkout.js',
35
+ PROD: 'https://js.antom.com/v2/ams-checkout.js'
35
36
  };
@@ -1,3 +1,8 @@
1
1
  import { EConstructorName, ProductType } from '../constant';
2
- export declare function loadSdk(): Promise<boolean>;
2
+ type SdkLoadResult = {
3
+ success: boolean;
4
+ loadType?: 'cached' | 'network';
5
+ };
6
+ export declare function loadSdk(): Promise<SdkLoadResult>;
3
7
  export declare function newActualInstance<T extends ProductType>(constructorName: EConstructorName, newProps: any): T | null;
8
+ export {};
@@ -12,10 +12,19 @@ export function loadSdk() {
12
12
  sdkSrc = (debugContext === null || debugContext === void 0 ? void 0 : debugContext.sdkUrl) || SDK_URL.PROD;
13
13
  }
14
14
 
15
+ // 校验URL合法性
16
+ try {
17
+ new URL(sdkSrc);
18
+ } catch (e) {
19
+ consoleLogger.error("Invalid SDK URL: ".concat(sdkSrc));
20
+ reject();
21
+ return;
22
+ }
23
+
15
24
  // 检查 SDK URL 是否存在
16
25
  if (!sdkSrc) {
17
26
  consoleLogger.error("SDK URL not found for: ".concat(sdkSrc));
18
- reject(false);
27
+ reject();
19
28
  return;
20
29
  }
21
30
 
@@ -23,7 +32,10 @@ export function loadSdk() {
23
32
  var existingScript = document.querySelector("script[src=\"".concat(sdkSrc, "\"]"));
24
33
  if (existingScript) {
25
34
  consoleLogger.log("SDK already loaded: ".concat(sdkSrc));
26
- resolve(true);
35
+ resolve({
36
+ success: true,
37
+ loadType: 'cached'
38
+ });
27
39
  return;
28
40
  }
29
41
 
@@ -35,7 +47,10 @@ export function loadSdk() {
35
47
  // 定义onload和onerror事件
36
48
  script.onload = function () {
37
49
  consoleLogger.log("Load SDK Success , SDK URL: ".concat(sdkSrc));
38
- resolve(true);
50
+ resolve({
51
+ success: true,
52
+ loadType: 'network'
53
+ });
39
54
  };
40
55
  script.onerror = function () {
41
56
  consoleLogger.log("Failed to load SDK: ".concat(sdkSrc));
@@ -44,7 +59,9 @@ export function loadSdk() {
44
59
  }, {
45
60
  sdkSrc: sdkSrc
46
61
  });
47
- reject(false);
62
+ // 失败时移除缓存脚本
63
+ script.remove();
64
+ reject();
48
65
  };
49
66
  });
50
67
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 在window对象上记录商户初始化SDK的StartTime,加载结束时间
3
+ * 后续传递给Web应用,用于进行端到端渲染总耗时计算
4
+ * ***/
5
+ import { ProductSceneEnum } from "../../types";
6
+ import { EConstructorName } from '../constant';
7
+ type TimeObject = {
8
+ startTime: number;
9
+ endTime: number;
10
+ };
11
+ /*** 扩展 Window 接口,添加 _ANTOM_SDK_PROXY_TIME 属性*/
12
+ declare global {
13
+ interface Window {
14
+ _ANTOM_SDK_PROXY_TIME?: Partial<Record<EConstructorName, TimeObject>>;
15
+ }
16
+ }
17
+ export declare function setProxyStartTime(constructorName: EConstructorName, startTime: number): number;
18
+ export declare function setProxyEndTime(constructorName: EConstructorName, endTime: number): number;
19
+ export declare const getProxyCostTime: (productScene: ProductSceneEnum) => number;
20
+ export {};
@@ -0,0 +1,66 @@
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
+ /**
3
+ * 在window对象上记录商户初始化SDK的StartTime,加载结束时间
4
+ * 后续传递给Web应用,用于进行端到端渲染总耗时计算
5
+ * ***/
6
+
7
+ import { ProductSceneEnum } from "../../types";
8
+
9
+ /*** 扩展 Window 接口,添加 _ANTOM_SDK_PROXY_TIME 属性*/
10
+
11
+ /*** 往window对象上注入全局变量 _ANTOM_SDK_PROXY_TIME */
12
+ function injectAntomSDKProxyStartTime() {
13
+ if (typeof window === 'undefined') {
14
+ return;
15
+ }
16
+ if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') {
17
+ window._ANTOM_SDK_PROXY_TIME = {};
18
+ }
19
+ return window._ANTOM_SDK_PROXY_TIME;
20
+ }
21
+ export function setProxyStartTime(constructorName, startTime) {
22
+ injectAntomSDKProxyStartTime();
23
+ if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') return startTime;
24
+ var timeObject = window._ANTOM_SDK_PROXY_TIME[constructorName];
25
+ if (_typeof(timeObject) !== 'object') {
26
+ window._ANTOM_SDK_PROXY_TIME[constructorName] = {
27
+ startTime: startTime,
28
+ endTime: 0
29
+ };
30
+ } else {
31
+ timeObject.startTime = startTime;
32
+ }
33
+ return startTime;
34
+ }
35
+ export function setProxyEndTime(constructorName, endTime) {
36
+ if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') return endTime;
37
+ var timeObject = window._ANTOM_SDK_PROXY_TIME[constructorName];
38
+ if (_typeof(timeObject) !== 'object') {
39
+ window._ANTOM_SDK_PROXY_TIME[constructorName] = {
40
+ startTime: 0,
41
+ endTime: endTime
42
+ };
43
+ } else {
44
+ timeObject.endTime = endTime;
45
+ }
46
+ return endTime;
47
+ }
48
+ export var getProxyCostTime = function getProxyCostTime(productScene) {
49
+ var _window, _window2, _timeObj, _timeObj2;
50
+ var timeObj;
51
+ switch (productScene) {
52
+ case ProductSceneEnum.ELEMENT_PAYMENT:
53
+ timeObj = (_window = window) === null || _window === void 0 || (_window = _window._ANTOM_SDK_PROXY_TIME) === null || _window === void 0 ? void 0 : _window['AMSElement'];
54
+ break;
55
+ case ProductSceneEnum.EASY_PAY:
56
+ timeObj = (_window2 = window) === null || _window2 === void 0 || (_window2 = _window2._ANTOM_SDK_PROXY_TIME) === null || _window2 === void 0 ? void 0 : _window2['AMSEasyPay'];
57
+ break;
58
+ default:
59
+ timeObj = {
60
+ startTime: 0,
61
+ endTime: 0
62
+ };
63
+ break;
64
+ }
65
+ return ((_timeObj = timeObj) === null || _timeObj === void 0 ? void 0 : _timeObj.endTime) - ((_timeObj2 = timeObj) === null || _timeObj2 === void 0 ? void 0 : _timeObj2.startTime) || 0;
66
+ };
@@ -15,6 +15,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
15
15
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
16
16
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
17
17
  */
18
+ import { getProxyCostTime } from "../../loader/utils/proxyPerformance";
18
19
  import { marmotMap, sdkVersion, v2AppMarmotMap } from "../../config/index";
19
20
  import { ComponentSignEnum, ComponentSignEnumV2 } from "../../types";
20
21
  import { isDebugLog } from "../../util/debug";
@@ -184,6 +185,7 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
184
185
  sdkVersion: sdkVersion,
185
186
  refUrl: window.location.href,
186
187
  _componentStartTime: "".concat(Date.now()),
188
+ _proxyCostTime: "".concat(getProxyCostTime(productScene)),
187
189
  isPreload: isPreload || '',
188
190
  hostSign: hostSign || ''
189
191
  });
@@ -18,13 +18,11 @@ export function injectAntomSDKIntegrationType(integrationType) {
18
18
  // 参数验证
19
19
  var validTypes = ['CDN', 'NPM'];
20
20
  if (!validTypes.includes(integrationType)) {
21
- console.warn("Integration type must be one of: ".concat(validTypes.join(', ')));
22
21
  return;
23
22
  }
24
23
 
25
24
  // 检查是否在浏览器环境中
26
25
  if (typeof window === 'undefined') {
27
- console.warn('window object is not available');
28
26
  return;
29
27
  }
30
28
 
@@ -39,7 +37,6 @@ export function injectAntomSDKIntegrationType(integrationType) {
39
37
  logger.setMedta({
40
38
  integrationType: integrationType
41
39
  });
42
- console.log("Successfully injected window._ANTOM_SDK_INTEGRATION_TYPE: ".concat(integrationType));
43
40
  }
44
41
 
45
42
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1762138227-dev.0",
3
+ "version": "0.0.1762138227-dev.10",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",
@@ -9,6 +9,7 @@
9
9
  "files": [
10
10
  "dist",
11
11
  "esm",
12
+ "ams-checkout.js",
12
13
  "LEGAL.md",
13
14
  "LICENSE",
14
15
  "README.md"