@alipay/ams-checkout 0.0.1762138227-dev.5 → 0.0.1762310209-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.
- 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 +0 -3
- package/esm/constant/index.js +0 -3
- package/esm/core/component/element/elementProcessor/addressProcessor.js +3 -2
- package/esm/core/component/element/elementProcessor/authProcessor.js +3 -2
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +1 -1
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +28 -30
- package/esm/foundation/core/index.js +0 -27
- package/esm/foundation/service/container/index.d.ts +0 -1
- package/esm/foundation/service/container/index.js +2 -33
- package/esm/foundation/utils/web_app_url_utils.d.ts +2 -0
- package/esm/foundation/utils/web_app_url_utils.js +15 -10
- package/esm/index.d.ts +52 -13
- package/esm/index.js +339 -19
- package/esm/plugin/component/cashierApp.js +4 -5
- package/esm/util/logger.d.ts +0 -2
- package/esm/util/logger.js +1 -1
- package/package.json +1 -6
- package/esm/constant/auto-debit.d.ts +0 -12
- package/esm/constant/auto-debit.js +0 -15
- package/esm/constant/element.d.ts +0 -26
- package/esm/constant/element.js +0 -30
- package/esm/loader/Proxy.d.ts +0 -5
- package/esm/loader/Proxy.js +0 -343
- package/esm/loader/constant.d.ts +0 -36
- package/esm/loader/constant.js +0 -36
- package/esm/loader/index.d.ts +0 -20
- package/esm/loader/index.js +0 -23
- package/esm/loader/utils/common.d.ts +0 -13
- package/esm/loader/utils/common.js +0 -63
- package/esm/loader/utils/debugger.d.ts +0 -7
- package/esm/loader/utils/debugger.js +0 -15
- package/esm/loader/utils/loadSDK.d.ts +0 -3
- package/esm/loader/utils/loadSDK.js +0 -75
- package/esm/loader/utils/logger.d.ts +0 -10
- package/esm/loader/utils/logger.js +0 -59
- package/esm/main.d.ts +0 -45
- package/esm/main.js +0 -329
- package/esm/util/integrationType.d.ts +0 -21
- package/esm/util/integrationType.js +0 -51
package/esm/loader/Proxy.js
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
-
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; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
-
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); }
|
|
13
|
-
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); }
|
|
14
|
-
/**
|
|
15
|
-
* Proxy代理层
|
|
16
|
-
* **/
|
|
17
|
-
import ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';
|
|
18
|
-
import { EConstructorName, instanceApiMap } from "./constant";
|
|
19
|
-
import { supportsDefineProperty, supportsProxy } from "./utils/common";
|
|
20
|
-
import { setDebugContext } from "./utils/debugger";
|
|
21
|
-
import { loadSdk, newActualInstance } from "./utils/loadSDK";
|
|
22
|
-
import { consoleLogger, logger } from "./utils/logger";
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line
|
|
31
|
-
export function createBaseProxy(constructorName) {
|
|
32
|
-
var _newProxyInstance = function _newProxyInstance(self) {
|
|
33
|
-
return new Proxy(self, {
|
|
34
|
-
get: function get(target, prop) {
|
|
35
|
-
// 如果是内部属性或方法,直接返回
|
|
36
|
-
if (prop in target || _typeof(prop) === 'symbol') {
|
|
37
|
-
return target[prop];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 返回一个代理方法
|
|
41
|
-
return function () {
|
|
42
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
|
-
args[_key] = arguments[_key];
|
|
44
|
-
}
|
|
45
|
-
// 已存在真实实例,直接调用
|
|
46
|
-
if (self.hasActualInstance && self.actualInstance) {
|
|
47
|
-
var _self$actualInstance;
|
|
48
|
-
return (_self$actualInstance = self.actualInstance)[prop].apply(_self$actualInstance, args);
|
|
49
|
-
} else {
|
|
50
|
-
// SDK未加载,记录调用
|
|
51
|
-
return new Promise(function (resolve, reject) {
|
|
52
|
-
consoleLogger.log("Cache API [".concat(constructorName, ".").concat(prop, "]"));
|
|
53
|
-
self.pendingCalls.push({
|
|
54
|
-
method: prop,
|
|
55
|
-
args: args,
|
|
56
|
-
resolve: resolve,
|
|
57
|
-
reject: reject
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
var _newProxyInstanceWithPolyfill = function _newProxyInstanceWithPolyfill(self) {
|
|
66
|
-
var proxyConstructor = ProxyPolyfillBuilder();
|
|
67
|
-
|
|
68
|
-
// 创建一个只读,不可调用,不可枚举的临时api,用于被proxyPolyfill捕获
|
|
69
|
-
var CAPTURED__API_TEMP_VALUE = Symbol('CAPTURED__API_TEMP_VALUE');
|
|
70
|
-
var needCapturedApis = instanceApiMap[constructorName];
|
|
71
|
-
needCapturedApis.forEach(function (api) {
|
|
72
|
-
Object.defineProperty(self, api, {
|
|
73
|
-
value: CAPTURED__API_TEMP_VALUE,
|
|
74
|
-
writable: false,
|
|
75
|
-
enumerable: false,
|
|
76
|
-
configurable: false
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
return new proxyConstructor(self, {
|
|
80
|
-
get: function get(target, prop) {
|
|
81
|
-
var proxyFunc = function proxyFunc() {
|
|
82
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
83
|
-
args[_key2] = arguments[_key2];
|
|
84
|
-
}
|
|
85
|
-
// 已存在真实实例,直接调用
|
|
86
|
-
if (self.hasActualInstance && self.actualInstance) {
|
|
87
|
-
var _self$actualInstance2;
|
|
88
|
-
return (_self$actualInstance2 = self.actualInstance)[prop].apply(_self$actualInstance2, args);
|
|
89
|
-
} else {
|
|
90
|
-
// SDK未加载,记录调用
|
|
91
|
-
return new Promise(function (resolve, reject) {
|
|
92
|
-
consoleLogger.log("Cache API [".concat(constructorName, ".").concat(prop, "]"));
|
|
93
|
-
self.pendingCalls.push({
|
|
94
|
-
method: prop,
|
|
95
|
-
args: args,
|
|
96
|
-
resolve: resolve,
|
|
97
|
-
reject: reject
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// 如果是需要代理的API 则返回一个代理方法
|
|
104
|
-
if ((target === null || target === void 0 ? void 0 : target[prop]) === CAPTURED__API_TEMP_VALUE) {
|
|
105
|
-
return proxyFunc;
|
|
106
|
-
}
|
|
107
|
-
// 如果是无需被代理的内部属性或方法,直接返回
|
|
108
|
-
if (prop in target || _typeof(prop) === 'symbol') {
|
|
109
|
-
return target[prop];
|
|
110
|
-
}
|
|
111
|
-
// 兜底
|
|
112
|
-
return proxyFunc;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/***构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象*/
|
|
118
|
-
var _newInstanceForError = function _newInstanceForError(errorObj) {
|
|
119
|
-
var instanceForError = {};
|
|
120
|
-
var needCapturedApis = instanceApiMap[constructorName];
|
|
121
|
-
needCapturedApis.forEach(function (api) {
|
|
122
|
-
instanceForError[api] = function () {
|
|
123
|
-
return Promise.resolve(errorObj);
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
return instanceForError;
|
|
127
|
-
};
|
|
128
|
-
var BaseProxy = /*#__PURE__*/function () {
|
|
129
|
-
// 返回代理实例对象
|
|
130
|
-
function BaseProxy(_newProps, debugProps) {
|
|
131
|
-
var _this = this;
|
|
132
|
-
_classCallCheck(this, BaseProxy);
|
|
133
|
-
_defineProperty(this, "hasActualInstance", false);
|
|
134
|
-
_defineProperty(this, "pendingCalls", []);
|
|
135
|
-
_defineProperty(this, "actualInstance", null);
|
|
136
|
-
_defineProperty(this, "proxyInstance", null);
|
|
137
|
-
_defineProperty(this, "startTime", 0);
|
|
138
|
-
_defineProperty(this, "onCreateInstanceError", function (newProps) {
|
|
139
|
-
// 不同实例进行不同的错误处理方案
|
|
140
|
-
if (constructorName === EConstructorName.AMSElement) {
|
|
141
|
-
_this.throwErrorWithPromise({
|
|
142
|
-
error: {
|
|
143
|
-
code: 'UI_STATE_ERROR',
|
|
144
|
-
message: 'create_actual_instance_error'
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
} else if (constructorName === EConstructorName.AMSEasyPay) {
|
|
148
|
-
_this.throwErrorWithOnEventCallback({
|
|
149
|
-
code: 'SDK_INTERNAL_ERROR',
|
|
150
|
-
message: 'create_actual_instance_error'
|
|
151
|
-
}, newProps);
|
|
152
|
-
} else {
|
|
153
|
-
_this.throwErrorWithOnEventCallback({
|
|
154
|
-
code: 'SDK_INTERNAL_ERROR',
|
|
155
|
-
message: 'create_actual_instance_error'
|
|
156
|
-
}, newProps);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
_defineProperty(this, "onLoadSDKError", function (newProps) {
|
|
160
|
-
if (constructorName === EConstructorName.AMSElement) {
|
|
161
|
-
_this.throwErrorWithPromise({
|
|
162
|
-
error: {
|
|
163
|
-
code: 'INITIALIZE_WEB_TIMEOUT',
|
|
164
|
-
message: 'load_sdk_resource_error'
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
} else if (constructorName === EConstructorName.AMSEasyPay) {
|
|
168
|
-
_this.throwErrorWithOnEventCallback({
|
|
169
|
-
code: 'SDK_INTERNAL_ERROR',
|
|
170
|
-
message: 'load_sdk_resource_error'
|
|
171
|
-
}, newProps);
|
|
172
|
-
} else {
|
|
173
|
-
_this.throwErrorWithOnEventCallback({
|
|
174
|
-
code: 'SDK_INTERNAL_ERROR',
|
|
175
|
-
message: 'load_sdk_resource_error'
|
|
176
|
-
}, newProps);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
this.startTime = Date.now();
|
|
180
|
-
|
|
181
|
-
// 初始化debug参数
|
|
182
|
-
setDebugContext(debugProps);
|
|
183
|
-
// 创建代理实例
|
|
184
|
-
this.proxyInstance = this.newProxyInstance();
|
|
185
|
-
// 加载sdk并创建真实实例
|
|
186
|
-
this.loadSDKAndCreateInstance(constructorName, _newProps);
|
|
187
|
-
logger.logInfo({
|
|
188
|
-
title: 'create_proxy_instance_success'
|
|
189
|
-
});
|
|
190
|
-
return this.proxyInstance;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// 初始化loader并开始加载sdk 创建实例,并执行所有待处理的调用
|
|
194
|
-
_createClass(BaseProxy, [{
|
|
195
|
-
key: "loadSDKAndCreateInstance",
|
|
196
|
-
value: function loadSDKAndCreateInstance(constructorName, newProps) {
|
|
197
|
-
var _this2 = this;
|
|
198
|
-
loadSdk().then(function () {
|
|
199
|
-
try {
|
|
200
|
-
var actualInstance = newActualInstance(constructorName, newProps);
|
|
201
|
-
// 从newProxy到初始化真实sdk实例花费时间
|
|
202
|
-
logger.logInfo({
|
|
203
|
-
title: 'report_customized_performance_m5'
|
|
204
|
-
}, {
|
|
205
|
-
m5: Date.now() - _this2.startTime
|
|
206
|
-
});
|
|
207
|
-
logger.logInfo({
|
|
208
|
-
title: 'create_actual_instance_success'
|
|
209
|
-
}, {
|
|
210
|
-
constructorName: constructorName
|
|
211
|
-
});
|
|
212
|
-
consoleLogger.log('create_actual_instance_success');
|
|
213
|
-
_this2.actualInstance = actualInstance;
|
|
214
|
-
_this2.hasActualInstance = true;
|
|
215
|
-
_this2.executePendingCalls();
|
|
216
|
-
} catch (error) {
|
|
217
|
-
_this2.onCreateInstanceError(newProps);
|
|
218
|
-
}
|
|
219
|
-
}).catch(function () {
|
|
220
|
-
_this2.onLoadSDKError(newProps);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// 创建代理实例
|
|
225
|
-
}, {
|
|
226
|
-
key: "newProxyInstance",
|
|
227
|
-
value: function newProxyInstance() {
|
|
228
|
-
// 检测浏览器API兼容性
|
|
229
|
-
var isProxySupports = supportsProxy();
|
|
230
|
-
var isDefinePropertySupports = supportsDefineProperty();
|
|
231
|
-
if (!isProxySupports && !isDefinePropertySupports) {
|
|
232
|
-
logger.logError({
|
|
233
|
-
title: 'create_proxy_instance_error'
|
|
234
|
-
});
|
|
235
|
-
consoleLogger.error('The browser does not support either Proxy or Object.defineProperty.');
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
239
|
-
var self = this;
|
|
240
|
-
|
|
241
|
-
// 如果浏览器不支持Proxy,则使用Polyfill降级 https://github.com/GoogleChrome/proxy-polyfill,
|
|
242
|
-
// 注意: Polyfill降级方案需要预先定义需要捕获的api。
|
|
243
|
-
if (isProxySupports) {
|
|
244
|
-
return _newProxyInstance(self);
|
|
245
|
-
} else {
|
|
246
|
-
logger.logInfo({
|
|
247
|
-
title: 'proxy_api_not_support'
|
|
248
|
-
});
|
|
249
|
-
return _newProxyInstanceWithPolyfill(self);
|
|
250
|
-
}
|
|
251
|
-
} catch (e) {
|
|
252
|
-
logger.logError({
|
|
253
|
-
title: 'create_proxy_instance_error'
|
|
254
|
-
}, {
|
|
255
|
-
errorMessage: e,
|
|
256
|
-
constructorName: constructorName
|
|
257
|
-
});
|
|
258
|
-
consoleLogger.error('The browser does not support either Proxy or Object.defineProperty.');
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// 执行所有待处理的调用
|
|
263
|
-
}, {
|
|
264
|
-
key: "executePendingCalls",
|
|
265
|
-
value: function executePendingCalls() {
|
|
266
|
-
while (this.pendingCalls.length > 0) {
|
|
267
|
-
if (!this.actualInstance) return;
|
|
268
|
-
var pendingCall = this.pendingCalls.shift();
|
|
269
|
-
if (!pendingCall) return;
|
|
270
|
-
var method = pendingCall.method,
|
|
271
|
-
args = pendingCall.args,
|
|
272
|
-
resolve = pendingCall.resolve,
|
|
273
|
-
reject = pendingCall.reject;
|
|
274
|
-
try {
|
|
275
|
-
var _this$actualInstance;
|
|
276
|
-
var result = (_this$actualInstance = this.actualInstance)[method].apply(_this$actualInstance, _toConsumableArray(args));
|
|
277
|
-
consoleLogger.log("call API [".concat(constructorName, ".").concat(method, "]"));
|
|
278
|
-
resolve(result);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
logger.logError({
|
|
281
|
-
title: 'call_pending_method_error'
|
|
282
|
-
}, {
|
|
283
|
-
errorMessage: error,
|
|
284
|
-
constructorName: constructorName,
|
|
285
|
-
method: method
|
|
286
|
-
});
|
|
287
|
-
reject(error);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
// 拒绝所有待处理的调用
|
|
292
|
-
}, {
|
|
293
|
-
key: "rejectPendingCalls",
|
|
294
|
-
value: function rejectPendingCalls(error) {
|
|
295
|
-
while (this.pendingCalls.length > 0) {
|
|
296
|
-
var pendingCall = this.pendingCalls.shift();
|
|
297
|
-
if (!pendingCall) return;
|
|
298
|
-
var reject = pendingCall.reject;
|
|
299
|
-
reject(error);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}, {
|
|
303
|
-
key: "throwErrorWithPromise",
|
|
304
|
-
value:
|
|
305
|
-
// 使用Promise.then来抛出错误对象 构造一个虚拟错误对象来模拟产品实例,其中所有的API都会在.then中返回错误对象
|
|
306
|
-
function throwErrorWithPromise(errorObj) {
|
|
307
|
-
var _errorObj$error;
|
|
308
|
-
var message = errorObj === null || errorObj === void 0 || (_errorObj$error = errorObj.error) === null || _errorObj$error === void 0 ? void 0 : _errorObj$error.message;
|
|
309
|
-
var instanceForError = _newInstanceForError(errorObj);
|
|
310
|
-
this.actualInstance = instanceForError;
|
|
311
|
-
this.hasActualInstance = true;
|
|
312
|
-
this.executePendingCalls();
|
|
313
|
-
logger.logError({
|
|
314
|
-
title: message
|
|
315
|
-
}, {
|
|
316
|
-
errorMessage: message,
|
|
317
|
-
constructorName: constructorName
|
|
318
|
-
});
|
|
319
|
-
consoleLogger.error(message);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// 使用onEventCallback向外抛出SDK内部错误
|
|
323
|
-
}, {
|
|
324
|
-
key: "throwErrorWithOnEventCallback",
|
|
325
|
-
value: function throwErrorWithOnEventCallback(errorObj, newProps) {
|
|
326
|
-
var onEventCallbackFn = newProps === null || newProps === void 0 ? void 0 : newProps.onEventCallback;
|
|
327
|
-
var message = errorObj.message;
|
|
328
|
-
if (typeof onEventCallbackFn === 'function') {
|
|
329
|
-
onEventCallbackFn === null || onEventCallbackFn === void 0 || onEventCallbackFn.call(null, errorObj);
|
|
330
|
-
}
|
|
331
|
-
logger.logError({
|
|
332
|
-
title: message
|
|
333
|
-
}, {
|
|
334
|
-
errorMessage: message,
|
|
335
|
-
constructorName: constructorName
|
|
336
|
-
});
|
|
337
|
-
consoleLogger.error(message);
|
|
338
|
-
}
|
|
339
|
-
}]);
|
|
340
|
-
return BaseProxy;
|
|
341
|
-
}();
|
|
342
|
-
return BaseProxy;
|
|
343
|
-
}
|
package/esm/loader/constant.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { AMSCashierPayment, AMSEasyPay, AMSElement } from '../main';
|
|
2
|
-
declare global {
|
|
3
|
-
interface Window {
|
|
4
|
-
AMSCashierPayment?: typeof AMSCashierPayment;
|
|
5
|
-
AMSElement?: typeof AMSElement;
|
|
6
|
-
AMSEasyPay?: typeof AMSEasyPay;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 产品类型
|
|
11
|
-
*/
|
|
12
|
-
export type ProductType = AMSCashierPayment | AMSEasyPay | AMSElement;
|
|
13
|
-
/**
|
|
14
|
-
* 产品构造函数
|
|
15
|
-
*/
|
|
16
|
-
export type ProductConstructor = typeof AMSCashierPayment | typeof AMSEasyPay | typeof AMSElement;
|
|
17
|
-
/**
|
|
18
|
-
* 产品构造函数名称枚举
|
|
19
|
-
*/
|
|
20
|
-
export declare enum EConstructorName {
|
|
21
|
-
AMSCashierPayment = "AMSCashierPayment",
|
|
22
|
-
AMSEasyPay = "AMSEasyPay",
|
|
23
|
-
AMSElement = "AMSElement"
|
|
24
|
-
}
|
|
25
|
-
export declare const instanceApiMap: Record<EConstructorName, string[]>;
|
|
26
|
-
/**
|
|
27
|
-
* SDK 集成类型枚举
|
|
28
|
-
*/
|
|
29
|
-
export type AntomWebSDKIntegrationType = 'CDN' | 'NPM';
|
|
30
|
-
/**
|
|
31
|
-
* SDK 地址
|
|
32
|
-
*/
|
|
33
|
-
export declare const SDK_URL: {
|
|
34
|
-
DEV: string;
|
|
35
|
-
PROD: string;
|
|
36
|
-
};
|
package/esm/loader/constant.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
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; }
|
|
3
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
|
-
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); }
|
|
5
|
-
/**
|
|
6
|
-
* 产品类型
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 产品构造函数
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 产品构造函数名称枚举
|
|
15
|
-
*/
|
|
16
|
-
export var EConstructorName = /*#__PURE__*/function (EConstructorName) {
|
|
17
|
-
EConstructorName["AMSCashierPayment"] = "AMSCashierPayment";
|
|
18
|
-
EConstructorName["AMSEasyPay"] = "AMSEasyPay";
|
|
19
|
-
EConstructorName["AMSElement"] = "AMSElement";
|
|
20
|
-
return EConstructorName;
|
|
21
|
-
}({});
|
|
22
|
-
|
|
23
|
-
// 这里维护各产品实例需要拦截的api列表,部分场景需要使用 (1.Polyfill需要预定义需要拦截的属性)
|
|
24
|
-
export var instanceApiMap = _defineProperty(_defineProperty(_defineProperty({}, EConstructorName.AMSCashierPayment, ['canMakePayments', 'createComponent', 'preloadComponent', 'mountComponent', 'submit']), EConstructorName.AMSEasyPay, ['createComponent', 'unmount']), EConstructorName.AMSElement, ['updatePayment', 'mount', 'submitPayment', 'destroy']);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* SDK 集成类型枚举
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* SDK 地址
|
|
32
|
-
*/
|
|
33
|
-
export var SDK_URL = {
|
|
34
|
-
DEV: 'http://js-dev.antom.com/v1/dist/umd/ams-checkout.min.js',
|
|
35
|
-
PROD: 'https://js.antom.com/v1/dist/umd/ams-checkout.min.js'
|
|
36
|
-
};
|
package/esm/loader/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 业务中间层
|
|
3
|
-
* 1.用于加载SDK & 实例化真实实例对象
|
|
4
|
-
* 2.解耦Proxy层与Wrapper层
|
|
5
|
-
* 3.预留给业务定制逻辑
|
|
6
|
-
* 4.类型适配
|
|
7
|
-
*/
|
|
8
|
-
import { AMSCashierPayment, AMSEasyPay, AMSElement } from '../main';
|
|
9
|
-
interface AMSCashierPaymentWrapper extends AMSCashierPayment {
|
|
10
|
-
preload: typeof AMSCashierPayment.preload;
|
|
11
|
-
}
|
|
12
|
-
interface AMSEasyPayWrapper extends AMSEasyPay {
|
|
13
|
-
preload: typeof AMSCashierPayment.preload;
|
|
14
|
-
}
|
|
15
|
-
interface AMSElementWrapper extends AMSElement {
|
|
16
|
-
}
|
|
17
|
-
declare const AMSCashierPaymentWrapper: typeof AMSCashierPayment;
|
|
18
|
-
declare const AMSEasyPayWrapper: typeof AMSEasyPay;
|
|
19
|
-
declare const AMSElementWrapper: typeof AMSElement;
|
|
20
|
-
export { AMSCashierPaymentWrapper, AMSEasyPayWrapper, AMSElementWrapper };
|
package/esm/loader/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 业务中间层
|
|
3
|
-
* 1.用于加载SDK & 实例化真实实例对象
|
|
4
|
-
* 2.解耦Proxy层与Wrapper层
|
|
5
|
-
* 3.预留给业务定制逻辑
|
|
6
|
-
* 4.类型适配
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { AMSCashierPayment, AMSEasyPay } from "../main";
|
|
10
|
-
import { EConstructorName } from "./constant";
|
|
11
|
-
import { createBaseProxy } from "./Proxy";
|
|
12
|
-
|
|
13
|
-
// 合并接口声明,让各Wrapper既是类型又是值,模拟class
|
|
14
|
-
|
|
15
|
-
// 真实创建proxy类
|
|
16
|
-
var AMSCashierPaymentWrapper = createBaseProxy(EConstructorName.AMSCashierPayment);
|
|
17
|
-
var AMSEasyPayWrapper = createBaseProxy(EConstructorName.AMSEasyPay);
|
|
18
|
-
var AMSElementWrapper = createBaseProxy(EConstructorName.AMSElement);
|
|
19
|
-
|
|
20
|
-
// 由于preload是静态方法, 需要直接挂载到构造函数上,这里不进行代理直接进行调用
|
|
21
|
-
AMSCashierPaymentWrapper.preload = AMSCashierPayment.preload;
|
|
22
|
-
AMSEasyPayWrapper.preload = AMSEasyPay.preload;
|
|
23
|
-
export { AMSCashierPaymentWrapper, AMSEasyPayWrapper, AMSElementWrapper };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 检测浏览器是否兼容Proxy对象
|
|
3
|
-
*/
|
|
4
|
-
export declare function supportsProxy(): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* 检测浏览器是否兼容defineProperty
|
|
7
|
-
*/
|
|
8
|
-
export declare function supportsDefineProperty(): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* @description 尝试调用window.tracker上报m5性能数据
|
|
11
|
-
* @param options 自定义性能埋点 m1-m20, m1-资源加载耗时,m2-首屏数据请求耗时,m3-首屏数据请求完成耗时,m4-首屏渲染完成耗时
|
|
12
|
-
*/
|
|
13
|
-
export declare const reportCustomizedPerformance: (options: any) => void;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logger";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 检测浏览器是否兼容Proxy对象
|
|
5
|
-
*/
|
|
6
|
-
export function supportsProxy() {
|
|
7
|
-
try {
|
|
8
|
-
// 检查 Proxy 构造函数是否存在
|
|
9
|
-
if (typeof Proxy === 'undefined') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 尝试创建一个简单的 Proxy
|
|
14
|
-
var testProxy = new Proxy({}, {
|
|
15
|
-
get: function get() {
|
|
16
|
-
return 'test';
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// 测试 Proxy 是否正常工作
|
|
21
|
-
return (testProxy === null || testProxy === void 0 ? void 0 : testProxy.anyProperty) === 'test';
|
|
22
|
-
} catch (e) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 检测浏览器是否兼容defineProperty
|
|
29
|
-
*/
|
|
30
|
-
export function supportsDefineProperty() {
|
|
31
|
-
if (typeof Object.defineProperty !== 'function') {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @description 尝试调用window.tracker上报m5性能数据
|
|
39
|
-
* @param options 自定义性能埋点 m1-m20, m1-资源加载耗时,m2-首屏数据请求耗时,m3-首屏数据请求完成耗时,m4-首屏渲染完成耗时
|
|
40
|
-
*/
|
|
41
|
-
export var reportCustomizedPerformance = function reportCustomizedPerformance(options) {
|
|
42
|
-
var retryCount = 0;
|
|
43
|
-
var maxRetries = 5;
|
|
44
|
-
var intervalId = setInterval(function () {
|
|
45
|
-
var _window;
|
|
46
|
-
retryCount++;
|
|
47
|
-
if ((_window = window) !== null && _window !== void 0 && _window.tracker) {
|
|
48
|
-
var _window2;
|
|
49
|
-
(_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.tracker) === null || _window2 === void 0 || _window2.reportCustomizedPerformanceData(options);
|
|
50
|
-
clearInterval(intervalId);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (retryCount >= maxRetries) {
|
|
54
|
-
clearInterval(intervalId);
|
|
55
|
-
logger.logError({
|
|
56
|
-
title: 'report_customized_performance_error'
|
|
57
|
-
}, {
|
|
58
|
-
options: options
|
|
59
|
-
});
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
}, 3000);
|
|
63
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全局debug上下文
|
|
3
|
-
* */
|
|
4
|
-
import { SDK_URL } from "../constant";
|
|
5
|
-
var debugContext = {
|
|
6
|
-
debugMode: false,
|
|
7
|
-
showLogger: true,
|
|
8
|
-
sdkUrl: SDK_URL.PROD // 默认为prod url
|
|
9
|
-
};
|
|
10
|
-
export var setDebugContext = function setDebugContext(props) {
|
|
11
|
-
Object.assign(debugContext, props || {});
|
|
12
|
-
};
|
|
13
|
-
export var getDebugContext = function getDebugContext() {
|
|
14
|
-
return debugContext;
|
|
15
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { SDK_URL } from "../constant";
|
|
2
|
-
import { getDebugContext } from "./debugger";
|
|
3
|
-
import { consoleLogger, logger } from "./logger";
|
|
4
|
-
export function loadSdk() {
|
|
5
|
-
return new Promise(function (resolve, reject) {
|
|
6
|
-
// 获取src
|
|
7
|
-
var sdkSrc = SDK_URL.PROD;
|
|
8
|
-
|
|
9
|
-
// debug模式动态传入sdkUrl
|
|
10
|
-
var debugContext = getDebugContext();
|
|
11
|
-
if ((debugContext === null || debugContext === void 0 ? void 0 : debugContext.debugMode) === true) {
|
|
12
|
-
sdkSrc = (debugContext === null || debugContext === void 0 ? void 0 : debugContext.sdkUrl) || SDK_URL.PROD;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// 检查 SDK URL 是否存在
|
|
16
|
-
if (!sdkSrc) {
|
|
17
|
-
consoleLogger.error("SDK URL not found for: ".concat(sdkSrc));
|
|
18
|
-
reject(false);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 检查是否已经加载过该脚本
|
|
23
|
-
var existingScript = document.querySelector("script[src=\"".concat(sdkSrc, "\"]"));
|
|
24
|
-
if (existingScript) {
|
|
25
|
-
consoleLogger.log("SDK already loaded: ".concat(sdkSrc));
|
|
26
|
-
resolve(true);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 注入脚本到html
|
|
31
|
-
var script = document.createElement('script');
|
|
32
|
-
script.src = sdkSrc;
|
|
33
|
-
document.head.appendChild(script);
|
|
34
|
-
|
|
35
|
-
// 定义onload和onerror事件
|
|
36
|
-
script.onload = function () {
|
|
37
|
-
consoleLogger.log("Load SDK Success , SDK URL: ".concat(sdkSrc));
|
|
38
|
-
resolve(true);
|
|
39
|
-
};
|
|
40
|
-
script.onerror = function () {
|
|
41
|
-
consoleLogger.log("Failed to load SDK: ".concat(sdkSrc));
|
|
42
|
-
logger.logError({
|
|
43
|
-
title: 'load_sdk_resource_error'
|
|
44
|
-
}, {
|
|
45
|
-
sdkSrc: sdkSrc
|
|
46
|
-
});
|
|
47
|
-
reject(false);
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
export function newActualInstance(constructorName, newProps) {
|
|
52
|
-
try {
|
|
53
|
-
var _window;
|
|
54
|
-
// 获取构造函数
|
|
55
|
-
if (!constructorName) {
|
|
56
|
-
consoleLogger.error("Load SDK failed: constructorName not found, please check constructorName: ".concat(constructorName));
|
|
57
|
-
logger.logError({
|
|
58
|
-
title: 'load_constructor_resource_error'
|
|
59
|
-
}, {
|
|
60
|
-
constructorName: constructorName
|
|
61
|
-
});
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
var Constructor = (_window = window) === null || _window === void 0 ? void 0 : _window[constructorName];
|
|
65
|
-
if (!Constructor) {
|
|
66
|
-
consoleLogger.error("".concat(constructorName, " not found after SDK load"));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 实例化对象
|
|
70
|
-
return new Constructor(newProps);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
consoleLogger.error('Load SDK failed:', error);
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../../util/logger';
|
|
2
|
-
export declare class ConsoleLogger {
|
|
3
|
-
show: boolean;
|
|
4
|
-
constructor(options: any);
|
|
5
|
-
log(message: string, ...args: any[]): void;
|
|
6
|
-
warn(message: string, ...args: any[]): void;
|
|
7
|
-
error(message: string, ...args: any[]): void;
|
|
8
|
-
}
|
|
9
|
-
export declare const consoleLogger: ConsoleLogger;
|
|
10
|
-
export declare const logger: Logger;
|