@alipay/ams-checkout 0.0.1709715270-dev.1 → 0.0.1709715270-dev.2
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/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +72 -0
- package/esm/core/bus/index.js +309 -0
- package/esm/core/bus/interface.d.ts +32 -0
- package/esm/core/bus/interface.js +35 -0
- package/esm/core/component/index.d.ts +7 -1
- package/esm/core/component/index.js +106 -17
- package/esm/core/instance/index.d.ts +1 -0
- package/esm/core/instance/index.js +2 -0
- package/esm/index.d.ts +0 -3
- package/esm/index.js +8 -18
- package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +16 -7
- package/esm/{core/applepay/index.js → plugin/applepay/component.js} +110 -131
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +100 -0
- package/esm/{common → plugin}/applepay/interface.d.ts +61 -0
- package/esm/plugin/applepay/interface.js +73 -0
- package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +5 -3
- package/esm/{common/applepay/index.js → plugin/applepay/service.js} +75 -20
- package/esm/plugin/component/index.d.ts +2 -2
- package/esm/plugin/component/index.js +9 -9
- package/esm/types/index.d.ts +45 -4
- package/package.json +1 -1
- package/esm/common/applepay/interface.js +0 -1
@@ -0,0 +1,309 @@
|
|
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
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 _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; }
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
+
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); } }
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
8
|
+
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; }
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
10
|
+
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); }
|
11
|
+
/**
|
12
|
+
* 扩展协议可序列化的消息定义
|
13
|
+
*/
|
14
|
+
export var BusMessage = /*#__PURE__*/function () {
|
15
|
+
function BusMessage(action, data) {
|
16
|
+
_classCallCheck(this, BusMessage);
|
17
|
+
_defineProperty(this, "action", void 0);
|
18
|
+
_defineProperty(this, "data", void 0);
|
19
|
+
_defineProperty(this, "jsonData", null);
|
20
|
+
this.action = action;
|
21
|
+
this.data = data;
|
22
|
+
}
|
23
|
+
_createClass(BusMessage, [{
|
24
|
+
key: "getAction",
|
25
|
+
value: function getAction() {
|
26
|
+
return this.action;
|
27
|
+
}
|
28
|
+
}, {
|
29
|
+
key: "getData",
|
30
|
+
value: function getData() {
|
31
|
+
return this.data;
|
32
|
+
}
|
33
|
+
}, {
|
34
|
+
key: "isJSONData",
|
35
|
+
value: function isJSONData() {
|
36
|
+
this.parseJSONData();
|
37
|
+
return this.jsonData !== null;
|
38
|
+
}
|
39
|
+
}, {
|
40
|
+
key: "getJSONObject",
|
41
|
+
value: function getJSONObject() {
|
42
|
+
var _this$jsonData;
|
43
|
+
this.parseJSONData();
|
44
|
+
return (_this$jsonData = this.jsonData) !== null && _this$jsonData !== void 0 ? _this$jsonData : {};
|
45
|
+
}
|
46
|
+
}, {
|
47
|
+
key: "parseJSONData",
|
48
|
+
value: function parseJSONData() {
|
49
|
+
if (this.jsonData === null) {
|
50
|
+
try {
|
51
|
+
this.jsonData = JSON.parse(this.data);
|
52
|
+
} catch (e) {
|
53
|
+
// handle error if JSON parsing fails
|
54
|
+
this.jsonData = null;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}, {
|
59
|
+
key: "result",
|
60
|
+
value: function result(_result) {
|
61
|
+
return new BusMessage(this.action, JSON.stringify(_result));
|
62
|
+
}
|
63
|
+
}]);
|
64
|
+
return BusMessage;
|
65
|
+
}();
|
66
|
+
/**
|
67
|
+
* 扩展总线可选的Context参数,在Web端用于实时回调
|
68
|
+
*/
|
69
|
+
export var BusContext = /*#__PURE__*/function () {
|
70
|
+
function BusContext(callback) {
|
71
|
+
_classCallCheck(this, BusContext);
|
72
|
+
_defineProperty(this, "callback", void 0);
|
73
|
+
this.callback = callback;
|
74
|
+
}
|
75
|
+
_createClass(BusContext, [{
|
76
|
+
key: "onCallBack",
|
77
|
+
value: function onCallBack(message) {
|
78
|
+
if (this.callback) {
|
79
|
+
this.callback(message);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}]);
|
83
|
+
return BusContext;
|
84
|
+
}();
|
85
|
+
|
86
|
+
/**
|
87
|
+
* 扩展能力的能力定义,基于此协议实现扩展能力
|
88
|
+
*/
|
89
|
+
export var BusSubscriber = /*#__PURE__*/_createClass(function BusSubscriber() {
|
90
|
+
_classCallCheck(this, BusSubscriber);
|
91
|
+
});
|
92
|
+
|
93
|
+
/**
|
94
|
+
* 拦截器,可增加扩展性
|
95
|
+
*/
|
96
|
+
|
97
|
+
/**
|
98
|
+
* 事件总线入口,支持的关系为:
|
99
|
+
* 发送者 和 接收者的关系: 一对一,大多数场景,支持callback
|
100
|
+
* 发送者 和 接收者的关系: 多对一, 设计上多一对,但是同一时间点,只会一个发送者,支持callback
|
101
|
+
* 发送者 和 接收者的关系: 一对多,可能有,埋点多重上报?不需要callback,业务场景应该是一个广播场景
|
102
|
+
*/
|
103
|
+
export var BusManager = /*#__PURE__*/function () {
|
104
|
+
function BusManager() {
|
105
|
+
_classCallCheck(this, BusManager);
|
106
|
+
}
|
107
|
+
_createClass(BusManager, null, [{
|
108
|
+
key: "debugTrace",
|
109
|
+
value: function debugTrace(enable) {
|
110
|
+
this.isDebug = enable;
|
111
|
+
}
|
112
|
+
}, {
|
113
|
+
key: "traceLog",
|
114
|
+
value: function traceLog(message) {
|
115
|
+
if (this.isDebug) {
|
116
|
+
for (var _len = arguments.length, optionalParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
117
|
+
optionalParams[_key - 1] = arguments[_key];
|
118
|
+
}
|
119
|
+
console.log([BusManager.TAG, message].concat(optionalParams).join(this._logSplit));
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}, {
|
123
|
+
key: "traceError",
|
124
|
+
value: function traceError(message) {
|
125
|
+
if (this.isDebug) {
|
126
|
+
for (var _len2 = arguments.length, optionalParams = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
127
|
+
optionalParams[_key2 - 1] = arguments[_key2];
|
128
|
+
}
|
129
|
+
console.error([BusManager.TAG, message].concat(optionalParams).join(this._logSplit));
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}, {
|
133
|
+
key: "clear",
|
134
|
+
value: function clear() {
|
135
|
+
BusManager.traceLog('clear');
|
136
|
+
BusManager.interceptors.length = 0;
|
137
|
+
BusManager.subscribersMap.clear();
|
138
|
+
}
|
139
|
+
}, {
|
140
|
+
key: "addInterceptor",
|
141
|
+
value: function addInterceptor(interceptor) {
|
142
|
+
BusManager.traceLog('addInterceptor');
|
143
|
+
if (!BusManager.interceptors.includes(interceptor)) {
|
144
|
+
BusManager.interceptors.push(interceptor);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}, {
|
148
|
+
key: "publishForResult",
|
149
|
+
value: function publishForResult(message, config) {
|
150
|
+
var _this = this;
|
151
|
+
return new Promise(function (resolve, reject) {
|
152
|
+
var _config$timeoutMs;
|
153
|
+
_this.publish(message, function (result) {
|
154
|
+
resolve(result);
|
155
|
+
});
|
156
|
+
setTimeout(function () {
|
157
|
+
if ((config === null || config === void 0 ? void 0 : config.fallback) !== null) {
|
158
|
+
resolve(message.result(config === null || config === void 0 ? void 0 : config.fallback));
|
159
|
+
} else {
|
160
|
+
reject('publish timeout');
|
161
|
+
}
|
162
|
+
}, (_config$timeoutMs = config === null || config === void 0 ? void 0 : config.timeoutMs) !== null && _config$timeoutMs !== void 0 ? _config$timeoutMs : 2000);
|
163
|
+
});
|
164
|
+
}
|
165
|
+
}, {
|
166
|
+
key: "publish",
|
167
|
+
value: function publish(message, callback) {
|
168
|
+
var _callBack = function _callBack(result) {
|
169
|
+
BusManager.traceLog('publish result ' + (message === null || message === void 0 ? void 0 : message.getAction()), result === null || result === void 0 ? void 0 : result.getData());
|
170
|
+
if (callback) {
|
171
|
+
callback(result);
|
172
|
+
}
|
173
|
+
};
|
174
|
+
var context = new BusContext(_callBack);
|
175
|
+
var actionName = message.getAction();
|
176
|
+
var subscribers = BusManager.subscribersMap.get(actionName);
|
177
|
+
BusManager.traceLog('publish', JSON.stringify(message));
|
178
|
+
if (subscribers) {
|
179
|
+
var _iterator = _createForOfIteratorHelper(subscribers),
|
180
|
+
_step;
|
181
|
+
try {
|
182
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
183
|
+
var subscriber = _step.value;
|
184
|
+
try {
|
185
|
+
subscriber.onMessage(context, message);
|
186
|
+
} catch (e) {
|
187
|
+
BusManager.traceError('excute onMessage error ', message, e);
|
188
|
+
var _iterator2 = _createForOfIteratorHelper(BusManager.interceptors),
|
189
|
+
_step2;
|
190
|
+
try {
|
191
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
192
|
+
var interceptor = _step2.value;
|
193
|
+
interceptor === null || interceptor === void 0 || interceptor.onPublishException(message, e);
|
194
|
+
}
|
195
|
+
} catch (err) {
|
196
|
+
_iterator2.e(err);
|
197
|
+
} finally {
|
198
|
+
_iterator2.f();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
} catch (err) {
|
203
|
+
_iterator.e(err);
|
204
|
+
} finally {
|
205
|
+
_iterator.f();
|
206
|
+
}
|
207
|
+
} else {
|
208
|
+
var handle = false;
|
209
|
+
var _iterator3 = _createForOfIteratorHelper(BusManager.interceptors),
|
210
|
+
_step3;
|
211
|
+
try {
|
212
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
213
|
+
var _interceptor = _step3.value;
|
214
|
+
BusManager.traceLog('onUnsubscribedAction', JSON.stringify(message));
|
215
|
+
handle = handle || (_interceptor === null || _interceptor === void 0 ? void 0 : _interceptor.onUnsubscribedAction(message.getAction()));
|
216
|
+
}
|
217
|
+
} catch (err) {
|
218
|
+
_iterator3.e(err);
|
219
|
+
} finally {
|
220
|
+
_iterator3.f();
|
221
|
+
}
|
222
|
+
if (handle) {
|
223
|
+
BusManager.publish(message, callback); // Re-publish the message
|
224
|
+
} else {
|
225
|
+
BusManager.traceError('notSubscribeMessage', JSON.stringify(message));
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}, {
|
230
|
+
key: "subscribe",
|
231
|
+
value: function subscribe(subscriber) {
|
232
|
+
BusManager.traceLog('subscribe', subscriber === null || subscriber === void 0 ? void 0 : subscriber.actionNames());
|
233
|
+
var _iterator4 = _createForOfIteratorHelper(subscriber.actionNames()),
|
234
|
+
_step4;
|
235
|
+
try {
|
236
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
237
|
+
var _actionName = _step4.value;
|
238
|
+
if (!BusManager.subscribersMap.has(_actionName)) {
|
239
|
+
BusManager.subscribersMap.set(_actionName, []);
|
240
|
+
}
|
241
|
+
var subscribers = BusManager.subscribersMap.get(_actionName);
|
242
|
+
if (subscribers && !subscribers.includes(subscriber)) {
|
243
|
+
subscribers.push(subscriber);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
} catch (err) {
|
247
|
+
_iterator4.e(err);
|
248
|
+
} finally {
|
249
|
+
_iterator4.f();
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}, {
|
253
|
+
key: "unsubscribe",
|
254
|
+
value: function unsubscribe(subscriber) {
|
255
|
+
BusManager.traceLog('unsubscribe', subscriber === null || subscriber === void 0 ? void 0 : subscriber.actionNames());
|
256
|
+
var _iterator5 = _createForOfIteratorHelper(subscriber.actionNames()),
|
257
|
+
_step5;
|
258
|
+
try {
|
259
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
260
|
+
var _actionName2 = _step5.value;
|
261
|
+
var subscribers = BusManager.subscribersMap.get(_actionName2);
|
262
|
+
if (subscribers) {
|
263
|
+
var index = subscribers.indexOf(subscriber);
|
264
|
+
if (index !== -1) {
|
265
|
+
subscribers.splice(index, 1);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
}
|
269
|
+
} catch (err) {
|
270
|
+
_iterator5.e(err);
|
271
|
+
} finally {
|
272
|
+
_iterator5.f();
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}, {
|
276
|
+
key: "isSubscribed",
|
277
|
+
value: function isSubscribed(actionName) {
|
278
|
+
var subscribers = BusManager.subscribersMap.get(actionName);
|
279
|
+
if (subscribers && subscribers.length > 0) {
|
280
|
+
BusManager.traceLog('isSubscribed: ' + actionName, true);
|
281
|
+
return true;
|
282
|
+
}
|
283
|
+
var handle = false;
|
284
|
+
var _iterator6 = _createForOfIteratorHelper(BusManager.interceptors),
|
285
|
+
_step6;
|
286
|
+
try {
|
287
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
288
|
+
var interceptor = _step6.value;
|
289
|
+
handle = handle || interceptor.onUnsubscribedAction(actionName);
|
290
|
+
}
|
291
|
+
} catch (err) {
|
292
|
+
_iterator6.e(err);
|
293
|
+
} finally {
|
294
|
+
_iterator6.f();
|
295
|
+
}
|
296
|
+
if (handle) {
|
297
|
+
return BusManager.subscribersMap.has(actionName);
|
298
|
+
}
|
299
|
+
BusManager.traceLog('isSubscribed: ' + actionName, false);
|
300
|
+
return false;
|
301
|
+
}
|
302
|
+
}]);
|
303
|
+
return BusManager;
|
304
|
+
}();
|
305
|
+
_defineProperty(BusManager, "TAG", 'BusManager');
|
306
|
+
_defineProperty(BusManager, "_logSplit", ' , ');
|
307
|
+
_defineProperty(BusManager, "interceptors", []);
|
308
|
+
_defineProperty(BusManager, "subscribersMap", new Map());
|
309
|
+
_defineProperty(BusManager, "isDebug", true);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export declare enum PaymentActionEnum {
|
2
|
+
optional_init = "plugin_optional_init"
|
3
|
+
}
|
4
|
+
export declare enum ApplePayActionEnum {
|
5
|
+
canMakePayments = "plugin_CARD_APPLE_PAY_available",
|
6
|
+
createComponent = "plugin_CARD_APPLE_PAY_createComponent",
|
7
|
+
destoryComponent = "plugin_CARD_APPLE_PAY_destoryComponent"
|
8
|
+
}
|
9
|
+
export declare enum SDKCallbackActionEnum {
|
10
|
+
onEventCallback = "onEventCallback"
|
11
|
+
}
|
12
|
+
export declare enum SecuritySDKActionEnum {
|
13
|
+
getSecurityDeviceId = "getSecurityDeviceId"
|
14
|
+
}
|
15
|
+
export declare enum TrackerActionEnum {
|
16
|
+
/**
|
17
|
+
* level: string info/error
|
18
|
+
* basic: json object
|
19
|
+
* extra: json object
|
20
|
+
*/
|
21
|
+
reportAnalytics = "reportAnalytics"
|
22
|
+
}
|
23
|
+
export declare enum ComponentActiontEnum {
|
24
|
+
onDestory = "onDestory"
|
25
|
+
}
|
26
|
+
export declare enum RequestActiontEnum {
|
27
|
+
onDestory = "httpRequest"
|
28
|
+
}
|
29
|
+
export declare enum LoadingActiontEnum {
|
30
|
+
showLoading = "showLoading",
|
31
|
+
dismissLoading = "dismissLoading"
|
32
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
export var PaymentActionEnum = /*#__PURE__*/function (PaymentActionEnum) {
|
2
|
+
PaymentActionEnum["optional_init"] = "plugin_optional_init";
|
3
|
+
return PaymentActionEnum;
|
4
|
+
}({});
|
5
|
+
export var ApplePayActionEnum = /*#__PURE__*/function (ApplePayActionEnum) {
|
6
|
+
ApplePayActionEnum["canMakePayments"] = "plugin_CARD_APPLE_PAY_available";
|
7
|
+
ApplePayActionEnum["createComponent"] = "plugin_CARD_APPLE_PAY_createComponent";
|
8
|
+
ApplePayActionEnum["destoryComponent"] = "plugin_CARD_APPLE_PAY_destoryComponent";
|
9
|
+
return ApplePayActionEnum;
|
10
|
+
}({});
|
11
|
+
export var SDKCallbackActionEnum = /*#__PURE__*/function (SDKCallbackActionEnum) {
|
12
|
+
SDKCallbackActionEnum["onEventCallback"] = "onEventCallback";
|
13
|
+
return SDKCallbackActionEnum;
|
14
|
+
}({});
|
15
|
+
export var SecuritySDKActionEnum = /*#__PURE__*/function (SecuritySDKActionEnum) {
|
16
|
+
SecuritySDKActionEnum["getSecurityDeviceId"] = "getSecurityDeviceId";
|
17
|
+
return SecuritySDKActionEnum;
|
18
|
+
}({});
|
19
|
+
export var TrackerActionEnum = /*#__PURE__*/function (TrackerActionEnum) {
|
20
|
+
TrackerActionEnum["reportAnalytics"] = "reportAnalytics";
|
21
|
+
return TrackerActionEnum;
|
22
|
+
}({});
|
23
|
+
export var ComponentActiontEnum = /*#__PURE__*/function (ComponentActiontEnum) {
|
24
|
+
ComponentActiontEnum["onDestory"] = "onDestory";
|
25
|
+
return ComponentActiontEnum;
|
26
|
+
}({});
|
27
|
+
export var RequestActiontEnum = /*#__PURE__*/function (RequestActiontEnum) {
|
28
|
+
RequestActiontEnum["onDestory"] = "httpRequest";
|
29
|
+
return RequestActiontEnum;
|
30
|
+
}({});
|
31
|
+
export var LoadingActiontEnum = /*#__PURE__*/function (LoadingActiontEnum) {
|
32
|
+
LoadingActiontEnum["showLoading"] = "showLoading";
|
33
|
+
LoadingActiontEnum["dismissLoading"] = "dismissLoading";
|
34
|
+
return LoadingActiontEnum;
|
35
|
+
}({});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import ComponentApp from '../../plugin/component';
|
2
|
-
import { componentSignEnum, IcreateComponent, IoptionsParams, IpaymentSessionMetaData, Iselector, Isubmit } from '../../types';
|
2
|
+
import { componentSignEnum, IcreateComponent, IoptionsParams, IpaymentSessionMetaData, Iselector, Isubmit, PaymentMethodTypeEnum, SubPaymentMethodTypeEnum } from '../../types';
|
3
3
|
import CoreInstance from '../instance/index';
|
4
4
|
export declare const getComponentSign: (params: IpaymentSessionMetaData) => componentSignEnum;
|
5
5
|
export declare const parseSessionData: (sessionData: string) => [IpaymentSessionMetaData, string];
|
@@ -11,11 +11,17 @@ export declare class AMSComponent extends CoreInstance {
|
|
11
11
|
private parameterInitAndCheck;
|
12
12
|
private pluginAppendIframe;
|
13
13
|
private savePreviousChannel;
|
14
|
+
/**
|
15
|
+
* 初始化 Bus总线的能力
|
16
|
+
*/
|
17
|
+
private registerBusAbility;
|
18
|
+
canMakePayments(paymentMethod: PaymentMethodTypeEnum, subPaymentMethod: SubPaymentMethodTypeEnum): Promise<boolean>;
|
14
19
|
/**
|
15
20
|
* @description Create component application
|
16
21
|
* @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
|
17
22
|
*/
|
18
23
|
createComponent(params: IcreateComponent): Promise<void>;
|
24
|
+
private isApplePay;
|
19
25
|
preloadComponent(channelType: any, productSceneVersion: any): void;
|
20
26
|
clearPreloadIframe(isTimeOut?: boolean): void;
|
21
27
|
/**
|
@@ -1,4 +1,6 @@
|
|
1
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
2
4
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
3
5
|
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); } }
|
4
6
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
@@ -28,11 +30,17 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
30
|
import { v4 as uuid } from 'uuid';
|
29
31
|
import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
|
30
32
|
import ComponentApp from "../../plugin/component";
|
31
|
-
import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
|
33
|
+
import { componentSignEnum, environmentEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
|
32
34
|
import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
|
33
35
|
import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
|
34
36
|
import { getSecurityConfigStorageKey } from "../../util/security";
|
35
37
|
import CoreInstance from "../instance/index";
|
38
|
+
import { BusManager, BusMessage } from "../bus";
|
39
|
+
import { ApplePayActionEnum, PaymentActionEnum } from "../bus/interface";
|
40
|
+
import { SDKCallbackBusSubscriber } from "../bus/ability/callback";
|
41
|
+
import { ApplePayBusSubscriber } from "../../plugin/applepay";
|
42
|
+
import { SecurityBusSubscriber } from "../bus/ability/security";
|
43
|
+
import { TrackerBusSubscriber } from "../bus/ability/tracker";
|
36
44
|
export var getComponentSign = function getComponentSign(params) {
|
37
45
|
var _params$paymentSessio = params.paymentSessionConfig,
|
38
46
|
_params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
|
@@ -114,6 +122,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
114
122
|
// Register Cashier Application Plug in
|
115
123
|
_this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
|
116
124
|
_this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
|
125
|
+
_this.registerBusAbility();
|
117
126
|
return _this;
|
118
127
|
}
|
119
128
|
_createClass(AMSComponent, [{
|
@@ -188,6 +197,68 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
188
197
|
localStorage.setItem('antom_checkout_previousChannel', JSON.stringify(previousChannel));
|
189
198
|
}
|
190
199
|
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* 初始化 Bus总线的能力
|
203
|
+
*/
|
204
|
+
}, {
|
205
|
+
key: "registerBusAbility",
|
206
|
+
value: function registerBusAbility() {
|
207
|
+
var _this$originOptions,
|
208
|
+
_this2 = this;
|
209
|
+
BusManager.debugTrace(((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.environment) !== environmentEnum.prod);
|
210
|
+
BusManager.clear();
|
211
|
+
BusManager.addInterceptor({
|
212
|
+
onPublishException: function onPublishException(message, e) {
|
213
|
+
_this2.logger.logError({
|
214
|
+
title: 'onBusPublishException'
|
215
|
+
}, _objectSpread(_objectSpread({}, message), {}, {
|
216
|
+
errorMessage: JSON.stringify(e)
|
217
|
+
}));
|
218
|
+
}
|
219
|
+
});
|
220
|
+
// subscribe basic ablility
|
221
|
+
BusManager.subscribe(new SDKCallbackBusSubscriber(function (state) {
|
222
|
+
var _this2$_componentApp;
|
223
|
+
(_this2$_componentApp = _this2._componentApp) === null || _this2$_componentApp === void 0 || (_this2$_componentApp = _this2$_componentApp.AMSSDK) === null || _this2$_componentApp === void 0 || _this2$_componentApp._eventCenter.emit(EVENT.eventCallback.name, state);
|
224
|
+
}));
|
225
|
+
BusManager.subscribe(new SecurityBusSubscriber(function (deviceIdParameter, isPolling) {
|
226
|
+
var _this2$_componentApp2;
|
227
|
+
return (_this2$_componentApp2 = _this2._componentApp) === null || _this2$_componentApp2 === void 0 ? void 0 : _this2$_componentApp2.getDeviceIdAndLog(deviceIdParameter, isPolling);
|
228
|
+
}));
|
229
|
+
BusManager.subscribe(new TrackerBusSubscriber(this.logger));
|
230
|
+
// subscribe plugin
|
231
|
+
BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
|
232
|
+
// publish event
|
233
|
+
BusManager.publish(new BusMessage(PaymentActionEnum.optional_init, JSON.stringify(this.originOptions)));
|
234
|
+
}
|
235
|
+
}, {
|
236
|
+
key: "canMakePayments",
|
237
|
+
value: function canMakePayments(paymentMethod, subPaymentMethod) {
|
238
|
+
var _this3 = this;
|
239
|
+
// 判断支付方式是否可用
|
240
|
+
return new Promise(function (resolve) {
|
241
|
+
if (paymentMethod === 'ApplePay') {
|
242
|
+
BusManager.publishForResult(new BusMessage(ApplePayActionEnum.canMakePayments, JSON.stringify({
|
243
|
+
subPaymentMethod: subPaymentMethod
|
244
|
+
})), {
|
245
|
+
fallback: false
|
246
|
+
}).then(function (message) {
|
247
|
+
resolve(message.getJSONObject());
|
248
|
+
}).catch(function (e) {
|
249
|
+
_this3.logger.logInfo({
|
250
|
+
title: 'canMakePayments_error'
|
251
|
+
}, {
|
252
|
+
params: JSON.stringify(e)
|
253
|
+
});
|
254
|
+
resolve(false);
|
255
|
+
});
|
256
|
+
} else {
|
257
|
+
resolve(true);
|
258
|
+
}
|
259
|
+
});
|
260
|
+
}
|
261
|
+
|
191
262
|
/**
|
192
263
|
* @description Create component application
|
193
264
|
* @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
|
@@ -195,7 +266,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
195
266
|
}, {
|
196
267
|
key: "createComponent",
|
197
268
|
value: function createComponent(params) {
|
198
|
-
var
|
269
|
+
var _this4 = this;
|
199
270
|
this.clearPreloadIframe();
|
200
271
|
return this.parameterInitAndCheck({
|
201
272
|
params: params,
|
@@ -203,23 +274,41 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
203
274
|
}).then(function (_params) {
|
204
275
|
return handleParams(_params);
|
205
276
|
}).catch(function (error) {
|
206
|
-
|
277
|
+
_this4.logger.logError({
|
207
278
|
title: 'sdk_error_parameter'
|
208
279
|
}, {
|
209
280
|
params: JSON.stringify(params)
|
210
281
|
}).send();
|
211
|
-
|
282
|
+
_this4._eventCenter.emit(EVENT.error.name, error);
|
212
283
|
return Promise.reject(error);
|
213
284
|
}).then(function (appendParams) {
|
285
|
+
if (_this4.isApplePay(params === null || params === void 0 ? void 0 : params.paymentSessionData) && BusManager.isSubscribed(ApplePayActionEnum.createComponent)) {
|
286
|
+
// 执行出错了,在通用拦截器返回
|
287
|
+
BusManager.publish(new BusMessage(ApplePayActionEnum.createComponent, JSON.stringify({
|
288
|
+
paymentSessionData: params === null || params === void 0 ? void 0 : params.paymentSessionData,
|
289
|
+
options: _this4.originOptions
|
290
|
+
})));
|
291
|
+
return;
|
292
|
+
}
|
214
293
|
var iframeNodesParams = appendParams.iframeNodesParams;
|
215
|
-
|
216
|
-
return
|
294
|
+
_this4.savePreviousChannel(iframeNodesParams);
|
295
|
+
return _this4.pluginAppendIframe(appendParams);
|
217
296
|
});
|
218
297
|
}
|
298
|
+
}, {
|
299
|
+
key: "isApplePay",
|
300
|
+
value: function isApplePay(paymentSessionData) {
|
301
|
+
var _parseData$paymentSes2, _parseData$paymentSes3;
|
302
|
+
var _parseSessionData3 = parseSessionData(paymentSessionData),
|
303
|
+
_parseSessionData4 = _slicedToArray(_parseSessionData3, 2),
|
304
|
+
parseData = _parseSessionData4[0],
|
305
|
+
sessionData = _parseSessionData4[1];
|
306
|
+
return sessionData && (parseData === null || parseData === void 0 || (_parseData$paymentSes2 = parseData.paymentSessionConfig) === null || _parseData$paymentSes2 === void 0 ? void 0 : _parseData$paymentSes2.productScene) === productSceneEnum.CASHIER_PAYMENT && (parseData === null || parseData === void 0 || (_parseData$paymentSes3 = parseData.paymentSessionFactor) === null || _parseData$paymentSes3 === void 0 || (_parseData$paymentSes3 = _parseData$paymentSes3.paymentMethodInfo) === null || _parseData$paymentSes3 === void 0 ? void 0 : _parseData$paymentSes3.paymentMethodType) === "CARD_APPLE_PAY";
|
307
|
+
}
|
219
308
|
}, {
|
220
309
|
key: "preloadComponent",
|
221
310
|
value: function preloadComponent(channelType, productSceneVersion) {
|
222
|
-
var
|
311
|
+
var _this5 = this;
|
223
312
|
this.channelType = channelType;
|
224
313
|
this.productSceneVersion = productSceneVersion;
|
225
314
|
var MAX_CLEAR_TIME = 10000;
|
@@ -235,7 +324,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
235
324
|
});
|
236
325
|
}
|
237
326
|
setTimeout(function () {
|
238
|
-
|
327
|
+
_this5.clearPreloadIframe(true);
|
239
328
|
}, MAX_CLEAR_TIME);
|
240
329
|
}
|
241
330
|
}, {
|
@@ -266,7 +355,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
266
355
|
}, {
|
267
356
|
key: "mountComponent",
|
268
357
|
value: function mountComponent(params, selector) {
|
269
|
-
var
|
358
|
+
var _this6 = this;
|
270
359
|
this.clearPreloadIframe();
|
271
360
|
return this.parameterInitAndCheck({
|
272
361
|
params: params,
|
@@ -275,17 +364,17 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
275
364
|
}).then(function (_params) {
|
276
365
|
return handleParams(_params);
|
277
366
|
}).catch(function (error) {
|
278
|
-
|
367
|
+
_this6.logger.logError({
|
279
368
|
title: 'sdk_error_parameter'
|
280
369
|
}, {
|
281
370
|
params: JSON.stringify(params)
|
282
371
|
}).send();
|
283
|
-
|
372
|
+
_this6._eventCenter.emit(EVENT.error.name, error);
|
284
373
|
return Promise.reject(error);
|
285
374
|
}).then(function (appendParams) {
|
286
375
|
var iframeNodesParams = appendParams.iframeNodesParams;
|
287
|
-
|
288
|
-
return
|
376
|
+
_this6.savePreviousChannel(iframeNodesParams);
|
377
|
+
return _this6.pluginAppendIframe(appendParams);
|
289
378
|
});
|
290
379
|
}
|
291
380
|
/**
|
@@ -296,22 +385,22 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
296
385
|
}, {
|
297
386
|
key: "submit",
|
298
387
|
value: function submit(data) {
|
299
|
-
var
|
388
|
+
var _this7 = this;
|
300
389
|
return new Promise(function (resolve, reject) {
|
301
390
|
try {
|
302
391
|
var eventCallbackId = uuid();
|
303
392
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
304
|
-
|
393
|
+
_this7._eventCenter.once(eventCallbackId, function (_data) {
|
305
394
|
resolve(_data);
|
306
395
|
});
|
307
|
-
|
396
|
+
_this7._componentApp.dispatchToApp({
|
308
397
|
context: {
|
309
398
|
event: 'submitPay',
|
310
399
|
eventCallbackId: eventCallbackId,
|
311
400
|
data: data
|
312
401
|
}
|
313
402
|
});
|
314
|
-
|
403
|
+
_this7.logger.logInfo({
|
315
404
|
title: 'sdk_event_apiSubmit'
|
316
405
|
});
|
317
406
|
} catch (error) {
|
@@ -30,6 +30,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
30
30
|
function AMSSDK(options) {
|
31
31
|
_classCallCheck(this, AMSSDK);
|
32
32
|
_defineProperty(this, "options", void 0);
|
33
|
+
_defineProperty(this, "originOptions", void 0);
|
33
34
|
_defineProperty(this, "logger", void 0);
|
34
35
|
_defineProperty(this, "_eventCenter", void 0);
|
35
36
|
_defineProperty(this, "_instanceId", void 0);
|
@@ -37,6 +38,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
37
38
|
_defineProperty(this, "securitySdkMap", void 0);
|
38
39
|
_defineProperty(this, "plugins", void 0);
|
39
40
|
this._instanceId = uuid();
|
41
|
+
this.originOptions = options;
|
40
42
|
this.options = {};
|
41
43
|
this._eventCenter = new EventCenter();
|
42
44
|
this._initEvent(options);
|
package/esm/index.d.ts
CHANGED
@@ -5,15 +5,12 @@
|
|
5
5
|
* 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
|
6
6
|
* 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.
|
7
7
|
*/
|
8
|
-
import ApplePayComponent from './core/applepay';
|
9
8
|
import { AMSComponent } from './core/component/index';
|
10
9
|
import { IoptionsParams, componentSignEnum } from './types';
|
11
10
|
export * from './types';
|
12
11
|
export declare class AMSCheckout extends AMSComponent {
|
13
12
|
constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
|
14
13
|
}
|
15
|
-
export declare class AMSApplePay extends ApplePayComponent {
|
16
|
-
}
|
17
14
|
export declare class AMSAutoDebit extends AMSCheckout {
|
18
15
|
constructor(options: IoptionsParams);
|
19
16
|
}
|