@alipay/ams-checkout 0.0.1762138227-dev.0 → 0.0.1762138227-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.
Files changed (2) hide show
  1. package/esm/loader/Proxy.js +87 -43
  2. package/package.json +1 -1
@@ -15,7 +15,7 @@ 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";
@@ -29,6 +29,7 @@ import { consoleLogger, logger } from "./utils/logger";
29
29
 
30
30
  // eslint-disable-next-line
31
31
  export function createBaseProxy(constructorName) {
32
+ var _this = this;
32
33
  var _newProxyInstance = function _newProxyInstance(self) {
33
34
  return new Proxy(self, {
34
35
  get: function get(target, prop) {
@@ -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,
@@ -123,6 +126,81 @@ export function createBaseProxy(constructorName) {
123
126
  });
124
127
  return instanceForError;
125
128
  };
129
+
130
+ // 使用Promise.then来抛出错误对象 构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
131
+ var throwErrorWithPromise = function throwErrorWithPromise(errorObj) {
132
+ var message = errorObj.error.message;
133
+ var instanceForError = _newInstanceForError(errorObj);
134
+ _this.actualInstance = instanceForError;
135
+ _this.hasActualInstance = true;
136
+ _this.executePendingCalls();
137
+ logger.logError({
138
+ title: message
139
+ }, {
140
+ errorMessage: message,
141
+ constructorName: constructorName
142
+ });
143
+ consoleLogger.error(message);
144
+ };
145
+
146
+ // 使用onEventCallback向外抛出SDK内部错误
147
+ var throwErrorWithOnEventCallback = function throwErrorWithOnEventCallback(errorObj, newProps) {
148
+ var onEventCallbackFn = newProps === null || newProps === void 0 ? void 0 : newProps.onEventCallback;
149
+ var message = errorObj.message;
150
+ if (typeof onEventCallbackFn === 'function') {
151
+ onEventCallbackFn === null || onEventCallbackFn === void 0 || onEventCallbackFn.call(null, errorObj);
152
+ }
153
+ logger.logError({
154
+ title: message
155
+ }, {
156
+ errorMessage: message,
157
+ constructorName: constructorName
158
+ });
159
+ consoleLogger.error(message);
160
+ };
161
+ var onCreateInstanceError = function onCreateInstanceError(newProps) {
162
+ // 不同实例进行不同的错误处理方案
163
+ if (constructorName === EConstructorName.AMSElement) {
164
+ throwErrorWithPromise({
165
+ error: {
166
+ code: 'INTERNAL_ERROR',
167
+ message: 'create_actual_instance_error'
168
+ },
169
+ status: 'FAIL'
170
+ });
171
+ } else if (constructorName === EConstructorName.AMSEasyPay) {
172
+ throwErrorWithOnEventCallback({
173
+ code: 'SDK_INTERNAL_ERROR',
174
+ message: 'create_actual_instance_error'
175
+ }, newProps);
176
+ } else {
177
+ throwErrorWithOnEventCallback({
178
+ code: 'SDK_INTERNAL_ERROR',
179
+ message: 'create_actual_instance_error'
180
+ }, newProps);
181
+ }
182
+ };
183
+ var onLoadSDKError = function onLoadSDKError(newProps) {
184
+ if (constructorName === EConstructorName.AMSElement) {
185
+ throwErrorWithPromise({
186
+ error: {
187
+ code: 'INITIALIZE_WEB_TIMEOUT',
188
+ message: 'load_sdk_resource_error'
189
+ },
190
+ status: 'FAIL'
191
+ });
192
+ } else if (constructorName === EConstructorName.AMSEasyPay) {
193
+ throwErrorWithOnEventCallback({
194
+ code: 'SDK_INTERNAL_ERROR',
195
+ message: 'load_sdk_resource_error'
196
+ }, newProps);
197
+ } else {
198
+ throwErrorWithOnEventCallback({
199
+ code: 'SDK_INTERNAL_ERROR',
200
+ message: 'load_sdk_resource_error'
201
+ }, newProps);
202
+ }
203
+ };
126
204
  var BaseProxy = /*#__PURE__*/function () {
127
205
  // 返回代理实例对象
128
206
  function BaseProxy(newProps, debugProps) {
@@ -150,7 +228,7 @@ export function createBaseProxy(constructorName) {
150
228
  _createClass(BaseProxy, [{
151
229
  key: "loadSDKAndCreateInstance",
152
230
  value: function loadSDKAndCreateInstance(constructorName, newProps) {
153
- var _this = this;
231
+ var _this2 = this;
154
232
  loadSdk().then(function () {
155
233
  try {
156
234
  var actualInstance = newActualInstance(constructorName, newProps);
@@ -158,7 +236,7 @@ export function createBaseProxy(constructorName) {
158
236
  logger.logInfo({
159
237
  title: 'report_customized_performance_m5'
160
238
  }, {
161
- m5: Date.now() - _this.startTime
239
+ m5: Date.now() - _this2.startTime
162
240
  });
163
241
  logger.logInfo({
164
242
  title: 'create_actual_instance_success'
@@ -166,48 +244,14 @@ export function createBaseProxy(constructorName) {
166
244
  constructorName: constructorName
167
245
  });
168
246
  consoleLogger.log('create_actual_instance_success');
169
- _this.actualInstance = actualInstance;
170
- _this.hasActualInstance = true;
171
- _this.executePendingCalls();
247
+ _this2.actualInstance = actualInstance;
248
+ _this2.hasActualInstance = true;
249
+ _this2.executePendingCalls();
172
250
  } 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'
186
- }, {
187
- errorMessage: error,
188
- constructorName: constructorName
189
- });
190
- consoleLogger.error('create_actual_instance_error');
251
+ onCreateInstanceError(newProps);
191
252
  }
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');
253
+ }).catch(function () {
254
+ onLoadSDKError(newProps);
211
255
  });
212
256
  }
213
257
 
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.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",