@alipay/ams-checkout 0.0.1762138227-dev.2 → 0.0.1762138227-dev.3

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 +85 -80
  2. package/package.json +1 -1
@@ -29,7 +29,6 @@ import { consoleLogger, logger } from "./utils/logger";
29
29
 
30
30
  // eslint-disable-next-line
31
31
  export function createBaseProxy(constructorName) {
32
- var _this = this;
33
32
  var _newProxyInstance = function _newProxyInstance(self) {
34
33
  return new Proxy(self, {
35
34
  get: function get(target, prop) {
@@ -126,90 +125,59 @@ export function createBaseProxy(constructorName) {
126
125
  });
127
126
  return instanceForError;
128
127
  };
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
- };
204
128
  var BaseProxy = /*#__PURE__*/function () {
205
129
  // 返回代理实例对象
206
- function BaseProxy(newProps, debugProps) {
130
+ function BaseProxy(_newProps, debugProps) {
131
+ var _this = this;
207
132
  _classCallCheck(this, BaseProxy);
208
133
  _defineProperty(this, "hasActualInstance", false);
209
134
  _defineProperty(this, "pendingCalls", []);
210
135
  _defineProperty(this, "actualInstance", null);
211
136
  _defineProperty(this, "proxyInstance", null);
212
137
  _defineProperty(this, "startTime", 0);
138
+ _defineProperty(this, "onCreateInstanceError", function (newProps) {
139
+ // 不同实例进行不同的错误处理方案
140
+ if (constructorName === EConstructorName.AMSElement) {
141
+ _this.throwErrorWithPromise({
142
+ error: {
143
+ code: 'INTERNAL_ERROR',
144
+ message: 'create_actual_instance_error'
145
+ },
146
+ status: 'FAIL'
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
+ status: 'FAIL'
168
+ });
169
+ } else if (constructorName === EConstructorName.AMSEasyPay) {
170
+ _this.throwErrorWithOnEventCallback({
171
+ code: 'SDK_INTERNAL_ERROR',
172
+ message: 'load_sdk_resource_error'
173
+ }, newProps);
174
+ } else {
175
+ _this.throwErrorWithOnEventCallback({
176
+ code: 'SDK_INTERNAL_ERROR',
177
+ message: 'load_sdk_resource_error'
178
+ }, newProps);
179
+ }
180
+ });
213
181
  this.startTime = Date.now();
214
182
 
215
183
  // 初始化debug参数
@@ -217,7 +185,7 @@ export function createBaseProxy(constructorName) {
217
185
  // 创建代理实例
218
186
  this.proxyInstance = this.newProxyInstance();
219
187
  // 加载sdk并创建真实实例
220
- this.loadSDKAndCreateInstance(constructorName, newProps);
188
+ this.loadSDKAndCreateInstance(constructorName, _newProps);
221
189
  logger.logInfo({
222
190
  title: 'create_proxy_instance_success'
223
191
  });
@@ -248,10 +216,10 @@ export function createBaseProxy(constructorName) {
248
216
  _this2.hasActualInstance = true;
249
217
  _this2.executePendingCalls();
250
218
  } catch (error) {
251
- onCreateInstanceError(newProps);
219
+ _this2.onCreateInstanceError(newProps);
252
220
  }
253
221
  }).catch(function () {
254
- onLoadSDKError(newProps);
222
+ _this2.onLoadSDKError(newProps);
255
223
  });
256
224
  }
257
225
 
@@ -333,6 +301,43 @@ export function createBaseProxy(constructorName) {
333
301
  reject(error);
334
302
  }
335
303
  }
304
+ }, {
305
+ key: "throwErrorWithPromise",
306
+ value:
307
+ // 使用Promise.then来抛出错误对象 构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
308
+ function throwErrorWithPromise(errorObj) {
309
+ var _errorObj$error;
310
+ var message = errorObj === null || errorObj === void 0 || (_errorObj$error = errorObj.error) === null || _errorObj$error === void 0 ? void 0 : _errorObj$error.message;
311
+ var instanceForError = _newInstanceForError(errorObj);
312
+ this.actualInstance = instanceForError;
313
+ this.hasActualInstance = true;
314
+ this.executePendingCalls();
315
+ logger.logError({
316
+ title: message
317
+ }, {
318
+ errorMessage: message,
319
+ constructorName: constructorName
320
+ });
321
+ consoleLogger.error(message);
322
+ }
323
+
324
+ // 使用onEventCallback向外抛出SDK内部错误
325
+ }, {
326
+ key: "throwErrorWithOnEventCallback",
327
+ value: function throwErrorWithOnEventCallback(errorObj, newProps) {
328
+ var onEventCallbackFn = newProps === null || newProps === void 0 ? void 0 : newProps.onEventCallback;
329
+ var message = errorObj.message;
330
+ if (typeof onEventCallbackFn === 'function') {
331
+ onEventCallbackFn === null || onEventCallbackFn === void 0 || onEventCallbackFn.call(null, errorObj);
332
+ }
333
+ logger.logError({
334
+ title: message
335
+ }, {
336
+ errorMessage: message,
337
+ constructorName: constructorName
338
+ });
339
+ consoleLogger.error(message);
340
+ }
336
341
  }]);
337
342
  return BaseProxy;
338
343
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1762138227-dev.2",
3
+ "version": "0.0.1762138227-dev.3",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",