@alipay/ams-checkout 0.0.1710212811-dev.1 → 0.0.1710212811-dev.11
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 +91 -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 +68 -0
- package/esm/core/bus/index.js +297 -0
- package/esm/core/bus/interface.d.ts +35 -0
- package/esm/core/bus/interface.js +39 -0
- package/esm/core/component/index.d.ts +7 -1
- package/esm/core/component/index.js +100 -17
- package/esm/core/instance/index.d.ts +1 -0
- package/esm/core/instance/index.js +2 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/{core/applepay/index.d.ts → plugin/applepay/component.d.ts} +13 -6
- package/esm/{core/applepay/index.js → plugin/applepay/component.js} +100 -170
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +101 -0
- package/esm/{common/applepay/index.d.ts → plugin/applepay/service.d.ts} +5 -4
- package/esm/{common/applepay/index.js → plugin/applepay/service.js} +25 -11
- package/esm/plugin/component/index.d.ts +2 -2
- package/esm/plugin/component/index.js +9 -9
- package/esm/types/index.d.ts +3 -3
- package/package.json +1 -1
- /package/esm/{common → plugin}/applepay/interface.d.ts +0 -0
- /package/esm/{common → plugin}/applepay/interface.js +0 -0
@@ -0,0 +1,297 @@
|
|
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
|
+
this.parseJSONData();
|
43
|
+
return this.jsonData;
|
44
|
+
}
|
45
|
+
}, {
|
46
|
+
key: "parseJSONData",
|
47
|
+
value: function parseJSONData() {
|
48
|
+
if (this.jsonData === null) {
|
49
|
+
try {
|
50
|
+
this.jsonData = JSON.parse(this.data);
|
51
|
+
} catch (e) {
|
52
|
+
// handle error if JSON parsing fails
|
53
|
+
this.jsonData = null;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}, {
|
58
|
+
key: "result",
|
59
|
+
value: function result(_result) {
|
60
|
+
return new BusMessage(this.action, JSON.stringify(_result));
|
61
|
+
}
|
62
|
+
}]);
|
63
|
+
return BusMessage;
|
64
|
+
}();
|
65
|
+
/**
|
66
|
+
* 扩展总线可选的Context参数,在Web端用于实时回调
|
67
|
+
*/
|
68
|
+
export var BusContext = /*#__PURE__*/function () {
|
69
|
+
function BusContext(callback) {
|
70
|
+
_classCallCheck(this, BusContext);
|
71
|
+
_defineProperty(this, "callback", void 0);
|
72
|
+
this.callback = callback;
|
73
|
+
}
|
74
|
+
_createClass(BusContext, [{
|
75
|
+
key: "onCallBack",
|
76
|
+
value: function onCallBack(message) {
|
77
|
+
if (this.callback) {
|
78
|
+
this.callback(message);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}]);
|
82
|
+
return BusContext;
|
83
|
+
}();
|
84
|
+
|
85
|
+
/**
|
86
|
+
* 扩展能力的能力定义,基于此协议实现扩展能力
|
87
|
+
*/
|
88
|
+
export var BusSubscriber = /*#__PURE__*/_createClass(function BusSubscriber() {
|
89
|
+
_classCallCheck(this, BusSubscriber);
|
90
|
+
});
|
91
|
+
|
92
|
+
/**
|
93
|
+
* 拦截器,可增加扩展性
|
94
|
+
*/
|
95
|
+
|
96
|
+
/**
|
97
|
+
* 事件总线入口,支持的关系为:
|
98
|
+
* 发送者 和 接收者的关系: 一对一,大多数场景,支持callback
|
99
|
+
* 发送者 和 接收者的关系: 多对一, 设计上多一对,但是同一时间点,只会一个发送者,支持callback
|
100
|
+
* 发送者 和 接收者的关系: 一对多,可能有,埋点多重上报?不需要callback,业务场景应该是一个广播场景
|
101
|
+
*/
|
102
|
+
export var BusManager = /*#__PURE__*/function () {
|
103
|
+
function BusManager() {
|
104
|
+
_classCallCheck(this, BusManager);
|
105
|
+
}
|
106
|
+
_createClass(BusManager, null, [{
|
107
|
+
key: "debugTrace",
|
108
|
+
value: function debugTrace(enable) {
|
109
|
+
this.isDebug = enable;
|
110
|
+
}
|
111
|
+
}, {
|
112
|
+
key: "traceLog",
|
113
|
+
value: function traceLog(message) {
|
114
|
+
if (this.isDebug) {
|
115
|
+
for (var _len = arguments.length, optionalParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
116
|
+
optionalParams[_key - 1] = arguments[_key];
|
117
|
+
}
|
118
|
+
console.log(message, optionalParams);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}, {
|
122
|
+
key: "traceError",
|
123
|
+
value: function traceError(message) {
|
124
|
+
if (this.isDebug) {
|
125
|
+
for (var _len2 = arguments.length, optionalParams = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
126
|
+
optionalParams[_key2 - 1] = arguments[_key2];
|
127
|
+
}
|
128
|
+
console.error(message, optionalParams);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}, {
|
132
|
+
key: "clear",
|
133
|
+
value: function clear() {
|
134
|
+
BusManager.traceLog(BusManager, 'clear');
|
135
|
+
BusManager.interceptors.length = 0;
|
136
|
+
BusManager.subscribersMap.clear();
|
137
|
+
}
|
138
|
+
}, {
|
139
|
+
key: "addInterceptor",
|
140
|
+
value: function addInterceptor(interceptor) {
|
141
|
+
BusManager.traceLog(BusManager, 'addInterceptor');
|
142
|
+
if (!BusManager.interceptors.includes(interceptor)) {
|
143
|
+
BusManager.interceptors.push(interceptor);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}, {
|
147
|
+
key: "publishForResult",
|
148
|
+
value: function publishForResult(message) {
|
149
|
+
var _this = this;
|
150
|
+
var timeoutMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000;
|
151
|
+
return new Promise(function (resolve, reject) {
|
152
|
+
_this.publish(message, function (result) {
|
153
|
+
resolve(result);
|
154
|
+
});
|
155
|
+
setTimeout(function () {
|
156
|
+
reject('publish timeout');
|
157
|
+
}, timeoutMs);
|
158
|
+
});
|
159
|
+
}
|
160
|
+
}, {
|
161
|
+
key: "publish",
|
162
|
+
value: function publish(message, callback) {
|
163
|
+
var context = new BusContext(callback);
|
164
|
+
var actionName = message.getAction();
|
165
|
+
var subscribers = BusManager.subscribersMap.get(actionName);
|
166
|
+
BusManager.traceLog(BusManager, 'publish', message);
|
167
|
+
if (subscribers) {
|
168
|
+
var _iterator = _createForOfIteratorHelper(subscribers),
|
169
|
+
_step;
|
170
|
+
try {
|
171
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
172
|
+
var subscriber = _step.value;
|
173
|
+
try {
|
174
|
+
subscriber.onMessage(context, message);
|
175
|
+
} catch (e) {
|
176
|
+
BusManager.traceError(BusManager, 'excute onMessage error ', message, e);
|
177
|
+
var _iterator2 = _createForOfIteratorHelper(BusManager.interceptors),
|
178
|
+
_step2;
|
179
|
+
try {
|
180
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
181
|
+
var interceptor = _step2.value;
|
182
|
+
interceptor === null || interceptor === void 0 || interceptor.onPublishException(message, e);
|
183
|
+
}
|
184
|
+
} catch (err) {
|
185
|
+
_iterator2.e(err);
|
186
|
+
} finally {
|
187
|
+
_iterator2.f();
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
} catch (err) {
|
192
|
+
_iterator.e(err);
|
193
|
+
} finally {
|
194
|
+
_iterator.f();
|
195
|
+
}
|
196
|
+
} else {
|
197
|
+
var handle = false;
|
198
|
+
var _iterator3 = _createForOfIteratorHelper(BusManager.interceptors),
|
199
|
+
_step3;
|
200
|
+
try {
|
201
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
202
|
+
var _interceptor = _step3.value;
|
203
|
+
BusManager.traceLog(BusManager, 'onUnsubscribedAction', message);
|
204
|
+
handle = handle || (_interceptor === null || _interceptor === void 0 ? void 0 : _interceptor.onUnsubscribedAction(message.getAction()));
|
205
|
+
}
|
206
|
+
} catch (err) {
|
207
|
+
_iterator3.e(err);
|
208
|
+
} finally {
|
209
|
+
_iterator3.f();
|
210
|
+
}
|
211
|
+
if (handle) {
|
212
|
+
BusManager.publish(message, callback); // Re-publish the message
|
213
|
+
} else {
|
214
|
+
BusManager.traceError(BusManager, 'notSubscribeMessage', message);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}, {
|
219
|
+
key: "subscribe",
|
220
|
+
value: function subscribe(subscriber) {
|
221
|
+
BusManager.traceLog(BusManager, 'subscribe', subscriber === null || subscriber === void 0 ? void 0 : subscriber.actionNames());
|
222
|
+
var _iterator4 = _createForOfIteratorHelper(subscriber.actionNames()),
|
223
|
+
_step4;
|
224
|
+
try {
|
225
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
226
|
+
var _actionName = _step4.value;
|
227
|
+
if (!BusManager.subscribersMap.has(_actionName)) {
|
228
|
+
BusManager.subscribersMap.set(_actionName, []);
|
229
|
+
}
|
230
|
+
var subscribers = BusManager.subscribersMap.get(_actionName);
|
231
|
+
if (subscribers && !subscribers.includes(subscriber)) {
|
232
|
+
subscribers.push(subscriber);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
} catch (err) {
|
236
|
+
_iterator4.e(err);
|
237
|
+
} finally {
|
238
|
+
_iterator4.f();
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}, {
|
242
|
+
key: "unsubscribe",
|
243
|
+
value: function unsubscribe(subscriber) {
|
244
|
+
BusManager.traceLog(BusManager, 'unsubscribe', subscriber === null || subscriber === void 0 ? void 0 : subscriber.actionNames());
|
245
|
+
var _iterator5 = _createForOfIteratorHelper(subscriber.actionNames()),
|
246
|
+
_step5;
|
247
|
+
try {
|
248
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
249
|
+
var _actionName2 = _step5.value;
|
250
|
+
var subscribers = BusManager.subscribersMap.get(_actionName2);
|
251
|
+
if (subscribers) {
|
252
|
+
var index = subscribers.indexOf(subscriber);
|
253
|
+
if (index !== -1) {
|
254
|
+
subscribers.splice(index, 1);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
}
|
258
|
+
} catch (err) {
|
259
|
+
_iterator5.e(err);
|
260
|
+
} finally {
|
261
|
+
_iterator5.f();
|
262
|
+
}
|
263
|
+
}
|
264
|
+
}, {
|
265
|
+
key: "isSubscribed",
|
266
|
+
value: function isSubscribed(actionName) {
|
267
|
+
var subscribers = BusManager.subscribersMap.get(actionName);
|
268
|
+
if (subscribers && subscribers.length > 0) {
|
269
|
+
BusManager.traceLog(BusManager, 'isSubscribed: ' + actionName, true);
|
270
|
+
return true;
|
271
|
+
}
|
272
|
+
var handle = false;
|
273
|
+
var _iterator6 = _createForOfIteratorHelper(BusManager.interceptors),
|
274
|
+
_step6;
|
275
|
+
try {
|
276
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
277
|
+
var interceptor = _step6.value;
|
278
|
+
handle = handle || interceptor.onUnsubscribedAction(actionName);
|
279
|
+
}
|
280
|
+
} catch (err) {
|
281
|
+
_iterator6.e(err);
|
282
|
+
} finally {
|
283
|
+
_iterator6.f();
|
284
|
+
}
|
285
|
+
if (handle) {
|
286
|
+
return BusManager.subscribersMap.has(actionName);
|
287
|
+
}
|
288
|
+
BusManager.traceLog(BusManager, 'isSubscribed: ' + actionName, false);
|
289
|
+
return false;
|
290
|
+
}
|
291
|
+
}]);
|
292
|
+
return BusManager;
|
293
|
+
}();
|
294
|
+
_defineProperty(BusManager, "TAG", 'BusManager');
|
295
|
+
_defineProperty(BusManager, "interceptors", []);
|
296
|
+
_defineProperty(BusManager, "subscribersMap", new Map());
|
297
|
+
_defineProperty(BusManager, "isDebug", true);
|
@@ -0,0 +1,35 @@
|
|
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 MonitorActiontEnum {
|
30
|
+
reportAnalytics = "reportAnalytics"
|
31
|
+
}
|
32
|
+
export declare enum LoadingActiontEnum {
|
33
|
+
showLoading = "showLoading",
|
34
|
+
dismissLoading = "dismissLoading"
|
35
|
+
}
|
@@ -0,0 +1,39 @@
|
|
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 MonitorActiontEnum = /*#__PURE__*/function (MonitorActiontEnum) {
|
32
|
+
MonitorActiontEnum["reportAnalytics"] = "reportAnalytics";
|
33
|
+
return MonitorActiontEnum;
|
34
|
+
}({});
|
35
|
+
export var LoadingActiontEnum = /*#__PURE__*/function (LoadingActiontEnum) {
|
36
|
+
LoadingActiontEnum["showLoading"] = "showLoading";
|
37
|
+
LoadingActiontEnum["dismissLoading"] = "dismissLoading";
|
38
|
+
return LoadingActiontEnum;
|
39
|
+
}({});
|
@@ -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
|
+
isApplePay(paymentSessionData: string): boolean;
|
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, PaymentMethodTypeEnum, 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,61 @@ 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
|
+
_this$originOptions2;
|
210
|
+
BusManager.debugTrace(((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.environment) !== environmentEnum.prod);
|
211
|
+
BusManager.clear();
|
212
|
+
BusManager.addInterceptor({
|
213
|
+
onPublishException: function onPublishException(message, e) {
|
214
|
+
_this2.logger.logInfo({
|
215
|
+
title: 'onPublishException'
|
216
|
+
}, _objectSpread(_objectSpread({}, message), {}, {
|
217
|
+
errorMessage: JSON.stringify(e)
|
218
|
+
}));
|
219
|
+
}
|
220
|
+
});
|
221
|
+
// subscribe basic ablility
|
222
|
+
BusManager.subscribe(new SDKCallbackBusSubscriber((_this$originOptions2 = this.originOptions) === null || _this$originOptions2 === void 0 ? void 0 : _this$originOptions2.onEventCallback));
|
223
|
+
BusManager.subscribe(new SecurityBusSubscriber(this._componentApp.getDeviceIdAndLog));
|
224
|
+
BusManager.subscribe(new TrackerBusSubscriber(this.logger));
|
225
|
+
// subscribe plugin
|
226
|
+
BusManager.subscribe(new ApplePayBusSubscriber(this.logger));
|
227
|
+
// publish devent
|
228
|
+
BusManager.publish(new BusMessage(PaymentActionEnum.optional_init, JSON.stringify(this.originOptions)));
|
229
|
+
}
|
230
|
+
}, {
|
231
|
+
key: "canMakePayments",
|
232
|
+
value: function canMakePayments(paymentMethod, subPaymentMethod) {
|
233
|
+
var _this3 = this;
|
234
|
+
// 判断支付方式是否可用
|
235
|
+
return new Promise(function (resolve) {
|
236
|
+
if (paymentMethod === PaymentMethodTypeEnum.ApplePay) {
|
237
|
+
BusManager.publishForResult(new BusMessage(ApplePayActionEnum.canMakePayments, JSON.stringify({
|
238
|
+
subPaymentMethod: subPaymentMethod
|
239
|
+
}))).then(function (message) {
|
240
|
+
resolve(message.getData() === 'true');
|
241
|
+
}).catch(function (e) {
|
242
|
+
_this3.logger.logInfo({
|
243
|
+
title: 'canMakePayments_error'
|
244
|
+
}, {
|
245
|
+
params: JSON.stringify(e)
|
246
|
+
});
|
247
|
+
resolve(false);
|
248
|
+
});
|
249
|
+
} else {
|
250
|
+
resolve(true);
|
251
|
+
}
|
252
|
+
});
|
253
|
+
}
|
254
|
+
|
191
255
|
/**
|
192
256
|
* @description Create component application
|
193
257
|
* @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 +259,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
195
259
|
}, {
|
196
260
|
key: "createComponent",
|
197
261
|
value: function createComponent(params) {
|
198
|
-
var
|
262
|
+
var _this4 = this;
|
199
263
|
this.clearPreloadIframe();
|
200
264
|
return this.parameterInitAndCheck({
|
201
265
|
params: params,
|
@@ -203,23 +267,42 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
203
267
|
}).then(function (_params) {
|
204
268
|
return handleParams(_params);
|
205
269
|
}).catch(function (error) {
|
206
|
-
|
270
|
+
_this4.logger.logError({
|
207
271
|
title: 'sdk_error_parameter'
|
208
272
|
}, {
|
209
273
|
params: JSON.stringify(params)
|
210
274
|
}).send();
|
211
|
-
|
275
|
+
_this4._eventCenter.emit(EVENT.error.name, error);
|
212
276
|
return Promise.reject(error);
|
213
277
|
}).then(function (appendParams) {
|
278
|
+
if (_this4.isApplePay(params === null || params === void 0 ? void 0 : params.paymentSessionData) && BusManager.isSubscribed(ApplePayActionEnum.createComponent)) {
|
279
|
+
// 执行出错了,在通用拦截器返回
|
280
|
+
BusManager.publish(new BusMessage(ApplePayActionEnum.createComponent, JSON.stringify({
|
281
|
+
paymentSessionData: params === null || params === void 0 ? void 0 : params.paymentSessionData,
|
282
|
+
options: _this4.originOptions
|
283
|
+
})));
|
284
|
+
return;
|
285
|
+
}
|
214
286
|
var iframeNodesParams = appendParams.iframeNodesParams;
|
215
|
-
|
216
|
-
return
|
287
|
+
_this4.savePreviousChannel(iframeNodesParams);
|
288
|
+
return _this4.pluginAppendIframe(appendParams);
|
217
289
|
});
|
218
290
|
}
|
291
|
+
}, {
|
292
|
+
key: "isApplePay",
|
293
|
+
value: function isApplePay(paymentSessionData) {
|
294
|
+
var _parseData$paymentSes2;
|
295
|
+
var _parseSessionData3 = parseSessionData(paymentSessionData),
|
296
|
+
_parseSessionData4 = _slicedToArray(_parseSessionData3, 2),
|
297
|
+
parseData = _parseSessionData4[0],
|
298
|
+
sessionData = _parseSessionData4[1];
|
299
|
+
// todo 补充全量判断
|
300
|
+
return sessionData && (parseData === null || parseData === void 0 || (_parseData$paymentSes2 = parseData.paymentSessionFactor) === null || _parseData$paymentSes2 === void 0 || (_parseData$paymentSes2 = _parseData$paymentSes2.paymentMethodInfo) === null || _parseData$paymentSes2 === void 0 ? void 0 : _parseData$paymentSes2.paymentMethodType) === "CARD_APPLE_PAY";
|
301
|
+
}
|
219
302
|
}, {
|
220
303
|
key: "preloadComponent",
|
221
304
|
value: function preloadComponent(channelType, productSceneVersion) {
|
222
|
-
var
|
305
|
+
var _this5 = this;
|
223
306
|
this.channelType = channelType;
|
224
307
|
this.productSceneVersion = productSceneVersion;
|
225
308
|
var MAX_CLEAR_TIME = 10000;
|
@@ -235,7 +318,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
235
318
|
});
|
236
319
|
}
|
237
320
|
setTimeout(function () {
|
238
|
-
|
321
|
+
_this5.clearPreloadIframe(true);
|
239
322
|
}, MAX_CLEAR_TIME);
|
240
323
|
}
|
241
324
|
}, {
|
@@ -266,7 +349,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
266
349
|
}, {
|
267
350
|
key: "mountComponent",
|
268
351
|
value: function mountComponent(params, selector) {
|
269
|
-
var
|
352
|
+
var _this6 = this;
|
270
353
|
this.clearPreloadIframe();
|
271
354
|
return this.parameterInitAndCheck({
|
272
355
|
params: params,
|
@@ -275,17 +358,17 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
275
358
|
}).then(function (_params) {
|
276
359
|
return handleParams(_params);
|
277
360
|
}).catch(function (error) {
|
278
|
-
|
361
|
+
_this6.logger.logError({
|
279
362
|
title: 'sdk_error_parameter'
|
280
363
|
}, {
|
281
364
|
params: JSON.stringify(params)
|
282
365
|
}).send();
|
283
|
-
|
366
|
+
_this6._eventCenter.emit(EVENT.error.name, error);
|
284
367
|
return Promise.reject(error);
|
285
368
|
}).then(function (appendParams) {
|
286
369
|
var iframeNodesParams = appendParams.iframeNodesParams;
|
287
|
-
|
288
|
-
return
|
370
|
+
_this6.savePreviousChannel(iframeNodesParams);
|
371
|
+
return _this6.pluginAppendIframe(appendParams);
|
289
372
|
});
|
290
373
|
}
|
291
374
|
/**
|
@@ -296,22 +379,22 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
|
|
296
379
|
}, {
|
297
380
|
key: "submit",
|
298
381
|
value: function submit(data) {
|
299
|
-
var
|
382
|
+
var _this7 = this;
|
300
383
|
return new Promise(function (resolve, reject) {
|
301
384
|
try {
|
302
385
|
var eventCallbackId = uuid();
|
303
386
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
304
|
-
|
387
|
+
_this7._eventCenter.once(eventCallbackId, function (_data) {
|
305
388
|
resolve(_data);
|
306
389
|
});
|
307
|
-
|
390
|
+
_this7._componentApp.dispatchToApp({
|
308
391
|
context: {
|
309
392
|
event: 'submitPay',
|
310
393
|
eventCallbackId: eventCallbackId,
|
311
394
|
data: data
|
312
395
|
}
|
313
396
|
});
|
314
|
-
|
397
|
+
_this7.logger.logInfo({
|
315
398
|
title: 'sdk_event_apiSubmit'
|
316
399
|
});
|
317
400
|
} 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,7 +5,7 @@
|
|
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 './
|
8
|
+
import ApplePayComponent from './plugin/applepay/component';
|
9
9
|
import { AMSComponent } from './core/component/index';
|
10
10
|
import { IoptionsParams, componentSignEnum } from './types';
|
11
11
|
export * from './types';
|
package/esm/index.js
CHANGED
@@ -18,7 +18,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
18
18
|
* 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
|
19
19
|
* 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.
|
20
20
|
*/
|
21
|
-
import ApplePayComponent from "./
|
21
|
+
import ApplePayComponent from "./plugin/applepay/component";
|
22
22
|
import { AMSComponent } from "./core/component/index";
|
23
23
|
import { componentSignEnum } from "./types";
|
24
24
|
import { productSceneEnum } from "./types/index";
|