@alipay/ams-checkout 0.0.1783663570-dev.5 → 0.0.1784095668-dev.0
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/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/esm/core/component/element/elementController/index.js +42 -66
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +10 -13
- package/esm/core/component/element/type.d.ts +1 -2
- package/esm/core/instance/index.d.ts +4 -12
- package/esm/core/instance/index.js +26 -152
- package/esm/foundation/service/security/index.d.ts +4 -9
- package/esm/foundation/service/security/index.js +35 -158
- package/esm/foundation/service/security/security.d.ts +1 -22
- package/esm/foundation/service/security/security.js +37 -150
- package/esm/foundation/utils/preload_helper.d.ts +3 -6
- package/esm/foundation/utils/preload_helper.js +32 -122
- package/esm/main.js +4 -4
- package/esm/modern/index.js +1 -1
- package/esm/plugin/component/channel.d.ts +2 -2
- package/esm/plugin/component/channel.js +18 -18
- package/esm/plugin/component/index.js +29 -36
- package/esm/util/beforeConfirm.d.ts +2 -4
- package/esm/util/beforeConfirm.js +14 -15
- package/esm/util/security.d.ts +1 -22
- package/esm/util/security.js +39 -150
- package/package.json +1 -1
- package/esm/util/jshield-apdid/apdid-loader.js +0 -340
- package/esm/util/jshield-apdid/index.js +0 -21
- package/esm/util/security-registry.d.ts +0 -72
- package/esm/util/security-registry.js +0 -175
|
@@ -37,7 +37,7 @@ import { ServiceProvider } from "../../../../foundation/service";
|
|
|
37
37
|
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
38
38
|
import { ProductSceneEnum } from "../../../../types";
|
|
39
39
|
import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
|
|
40
|
-
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS
|
|
40
|
+
import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
|
|
41
41
|
import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
|
|
42
42
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
|
43
43
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
@@ -233,7 +233,6 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
233
233
|
}, {
|
|
234
234
|
key: "initializeAndMountProcessor",
|
|
235
235
|
value: function initializeAndMountProcessor(type, selector, options) {
|
|
236
|
-
var _this$serviceMap$Log, _options$appearance;
|
|
237
236
|
this.initElementProcessors(type);
|
|
238
237
|
// 创建 iframe,拉起应用页面,同时监听全局的数据更新和获取事件
|
|
239
238
|
this.elementContainerService.mount({
|
|
@@ -249,12 +248,6 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
249
248
|
ServiceProvider.getInstance(newInstanceId).update(paymentContext);
|
|
250
249
|
// 更新埋点service
|
|
251
250
|
this.serviceMap.Log = ServiceProvider.getInstance(newInstanceId).getService('Log');
|
|
252
|
-
(_this$serviceMap$Log = this.serviceMap.Log) === null || _this$serviceMap$Log === void 0 || _this$serviceMap$Log.logInfo({
|
|
253
|
-
title: 'sdk_event_appearance'
|
|
254
|
-
}, {
|
|
255
|
-
variables: options !== null && options !== void 0 && (_options$appearance = options.appearance) !== null && _options$appearance !== void 0 && _options$appearance.variables ? true : false,
|
|
256
|
-
theme: options === null || options === void 0 ? void 0 : options.theme
|
|
257
|
-
});
|
|
258
251
|
this.elementProcessors[type].beforeMount();
|
|
259
252
|
}
|
|
260
253
|
// 处理业务流程启动失败
|
|
@@ -382,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
382
375
|
value: function () {
|
|
383
376
|
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
384
377
|
var _this3 = this;
|
|
385
|
-
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut,
|
|
378
|
+
var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
386
379
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
387
380
|
while (1) switch (_context4.prev = _context4.next) {
|
|
388
381
|
case 0:
|
|
@@ -412,7 +405,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
412
405
|
isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
|
|
413
406
|
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
414
407
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
415
|
-
_context4.next =
|
|
408
|
+
_context4.next = 34;
|
|
416
409
|
break;
|
|
417
410
|
}
|
|
418
411
|
this.serviceMap.Log.logInfo({
|
|
@@ -431,65 +424,49 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
431
424
|
_yield$executeWithTim = _context4.sent;
|
|
432
425
|
shouldContinue = _yield$executeWithTim.result;
|
|
433
426
|
timedOut = _yield$executeWithTim.timedOut;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
_context4.next = 24;
|
|
427
|
+
if (!(timedOut || !shouldContinue || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS)) {
|
|
428
|
+
_context4.next = 23;
|
|
437
429
|
break;
|
|
438
430
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
code: MERCHANT_CONFIRM_TIMEOUT_CODE,
|
|
454
|
-
message: 'Merchant confirmation timed out.',
|
|
455
|
-
needChangeSessionForRetry: false
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
case 24:
|
|
459
|
-
if (shouldContinue) {
|
|
460
|
-
_context4.next = 29;
|
|
461
|
-
break;
|
|
431
|
+
if (timedOut) {
|
|
432
|
+
this.serviceMap.Log.logError({
|
|
433
|
+
title: 'sdk_before_confirm_timeout'
|
|
434
|
+
}, {
|
|
435
|
+
paymentMethodType: paymentMethodType,
|
|
436
|
+
path: 'nonApplePay_sync'
|
|
437
|
+
});
|
|
438
|
+
} else {
|
|
439
|
+
this.serviceMap.Log.logInfo({
|
|
440
|
+
title: 'sdk_before_confirm_abort'
|
|
441
|
+
}, {
|
|
442
|
+
paymentMethodType: paymentMethodType,
|
|
443
|
+
path: 'nonApplePay_sync'
|
|
444
|
+
});
|
|
462
445
|
}
|
|
463
|
-
this.serviceMap.Log.logInfo({
|
|
464
|
-
title: 'sdk_before_confirm_abort'
|
|
465
|
-
}, {
|
|
466
|
-
paymentMethodType: paymentMethodType,
|
|
467
|
-
path: 'nonApplePay_sync'
|
|
468
|
-
});
|
|
469
446
|
this.changeLoading(false);
|
|
470
447
|
this.elementEventCenter.endEvent(startEventId, {
|
|
471
448
|
eventCode: PaymentStatus.FAIL,
|
|
472
|
-
errorName:
|
|
449
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
473
450
|
});
|
|
474
451
|
return _context4.abrupt("return", {
|
|
475
452
|
status: PaymentStatus.FAIL,
|
|
476
453
|
error: {
|
|
477
|
-
code:
|
|
478
|
-
message: '
|
|
454
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
455
|
+
message: 'Merchant canceled payment.',
|
|
479
456
|
needChangeSessionForRetry: false
|
|
480
457
|
}
|
|
481
458
|
});
|
|
482
|
-
case
|
|
459
|
+
case 23:
|
|
483
460
|
this.serviceMap.Log.logInfo({
|
|
484
461
|
title: 'sdk_before_confirm_success'
|
|
485
462
|
}, {
|
|
486
463
|
paymentMethodType: paymentMethodType,
|
|
487
464
|
path: 'nonApplePay_sync'
|
|
488
465
|
});
|
|
489
|
-
_context4.next =
|
|
466
|
+
_context4.next = 32;
|
|
490
467
|
break;
|
|
491
|
-
case
|
|
492
|
-
_context4.prev =
|
|
468
|
+
case 26:
|
|
469
|
+
_context4.prev = 26;
|
|
493
470
|
_context4.t0 = _context4["catch"](11);
|
|
494
471
|
this.serviceMap.Log.logError({
|
|
495
472
|
title: 'sdk_before_confirm_error'
|
|
@@ -501,20 +478,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
501
478
|
this.changeLoading(false);
|
|
502
479
|
this.elementEventCenter.endEvent(startEventId, {
|
|
503
480
|
eventCode: PaymentStatus.FAIL,
|
|
504
|
-
errorName:
|
|
481
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
505
482
|
});
|
|
506
483
|
return _context4.abrupt("return", {
|
|
507
484
|
status: PaymentStatus.FAIL,
|
|
508
485
|
error: {
|
|
509
|
-
code:
|
|
510
|
-
message: '
|
|
486
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
487
|
+
message: 'Merchant canceled payment.',
|
|
511
488
|
needChangeSessionForRetry: false
|
|
512
489
|
}
|
|
513
490
|
});
|
|
514
|
-
case
|
|
515
|
-
_context4.next =
|
|
491
|
+
case 32:
|
|
492
|
+
_context4.next = 35;
|
|
516
493
|
break;
|
|
517
|
-
case
|
|
494
|
+
case 34:
|
|
518
495
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
519
496
|
this.serviceMap.Log.logInfo({
|
|
520
497
|
title: 'sdk_before_confirm_skip'
|
|
@@ -523,10 +500,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
523
500
|
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
524
501
|
});
|
|
525
502
|
}
|
|
526
|
-
case
|
|
503
|
+
case 35:
|
|
527
504
|
recordResult = null;
|
|
528
|
-
_context4.prev =
|
|
529
|
-
_context4.next =
|
|
505
|
+
_context4.prev = 36;
|
|
506
|
+
_context4.next = 39;
|
|
530
507
|
return new Promise( /*#__PURE__*/function () {
|
|
531
508
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
532
509
|
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
@@ -615,8 +592,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
615
592
|
}, {
|
|
616
593
|
msg: safeStringify({
|
|
617
594
|
hasBeforeConfirmForApplePay: hasBeforeConfirmForApplePay,
|
|
618
|
-
isApplePay: isApplePay
|
|
619
|
-
amount: "".concat(submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount, ", ").concat(submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency)
|
|
595
|
+
isApplePay: isApplePay
|
|
620
596
|
})
|
|
621
597
|
});
|
|
622
598
|
_this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
|
|
@@ -684,10 +660,10 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
684
660
|
return _ref3.apply(this, arguments);
|
|
685
661
|
};
|
|
686
662
|
}());
|
|
687
|
-
case
|
|
663
|
+
case 39:
|
|
688
664
|
return _context4.abrupt("return", _context4.sent);
|
|
689
|
-
case
|
|
690
|
-
_context4.prev =
|
|
665
|
+
case 40:
|
|
666
|
+
_context4.prev = 40;
|
|
691
667
|
_logParams = {
|
|
692
668
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
693
669
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -698,12 +674,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
698
674
|
};
|
|
699
675
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
700
676
|
this.changeLoading(false);
|
|
701
|
-
return _context4.finish(
|
|
702
|
-
case
|
|
677
|
+
return _context4.finish(40);
|
|
678
|
+
case 45:
|
|
703
679
|
case "end":
|
|
704
680
|
return _context4.stop();
|
|
705
681
|
}
|
|
706
|
-
}, _callee4, this, [[11,
|
|
682
|
+
}, _callee4, this, [[11, 26], [36,, 40, 45]]);
|
|
707
683
|
}));
|
|
708
684
|
function submitPayment(_x) {
|
|
709
685
|
return _submitPayment.apply(this, arguments);
|
|
@@ -230,7 +230,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
230
230
|
// requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
|
|
231
231
|
// and returns the result (continue/abort) to iframe via dispatchToApp.
|
|
232
232
|
this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
233
|
-
var paymentMethodType, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue
|
|
233
|
+
var paymentMethodType, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
|
|
234
234
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
235
235
|
while (1) switch (_context.prev = _context.next) {
|
|
236
236
|
case 0:
|
|
@@ -270,9 +270,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
270
270
|
_yield$executeWithTim = _context.sent;
|
|
271
271
|
rawResult = _yield$executeWithTim.result;
|
|
272
272
|
timedOut = _yield$executeWithTim.timedOut;
|
|
273
|
-
shouldContinue = rawResult;
|
|
274
|
-
|
|
275
|
-
if (isTimeout) {
|
|
273
|
+
shouldContinue = rawResult; // 双重校验:timedOut(Promise race) + startTime(实际时间差),防止竞态误判
|
|
274
|
+
if (timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
276
275
|
logger.logError({
|
|
277
276
|
title: 'sdk_before_confirm_timeout'
|
|
278
277
|
});
|
|
@@ -285,17 +284,15 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
285
284
|
});
|
|
286
285
|
_this2.eventCenter.dispatchToApp({
|
|
287
286
|
event: EVENT.beforeConfirm.name,
|
|
288
|
-
data:
|
|
287
|
+
data: {
|
|
289
288
|
success: true,
|
|
290
289
|
result: !!shouldContinue
|
|
291
|
-
}
|
|
292
|
-
isTimeout: true
|
|
293
|
-
} : {})
|
|
290
|
+
}
|
|
294
291
|
});
|
|
295
|
-
_context.next =
|
|
292
|
+
_context.next = 23;
|
|
296
293
|
break;
|
|
297
|
-
case
|
|
298
|
-
_context.prev =
|
|
294
|
+
case 19:
|
|
295
|
+
_context.prev = 19;
|
|
299
296
|
_context.t0 = _context["catch"](6);
|
|
300
297
|
logger.logError({
|
|
301
298
|
title: 'sdk_before_confirm_error'
|
|
@@ -311,11 +308,11 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
311
308
|
result: false
|
|
312
309
|
}
|
|
313
310
|
});
|
|
314
|
-
case
|
|
311
|
+
case 23:
|
|
315
312
|
case "end":
|
|
316
313
|
return _context.stop();
|
|
317
314
|
}
|
|
318
|
-
}, _callee, null, [[6,
|
|
315
|
+
}, _callee, null, [[6, 19]]);
|
|
319
316
|
})));
|
|
320
317
|
}
|
|
321
318
|
}, {
|
|
@@ -352,8 +352,7 @@ export interface SubmitFuncParams {
|
|
|
352
352
|
* - Only effective when payment method is Apple Pay
|
|
353
353
|
* - Invoked via event bridge after user FaceID/TouchID authorization on the payment sheet
|
|
354
354
|
* - Return true: proceed with charge
|
|
355
|
-
* - Return false / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
|
|
356
|
-
* - Timeout: abort payment, returns MERCHANT_CONFIRM_TIMEOUT error code
|
|
355
|
+
* - Return false / timeout / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
|
|
357
356
|
*/
|
|
358
357
|
onBeforeConfirm?: () => Promise<boolean>;
|
|
359
358
|
}
|
|
@@ -11,7 +11,6 @@ import type { AMSCheckoutOptions, IAppendParams, InitSecurityConfig, IoptionsPar
|
|
|
11
11
|
import { EventCenter } from '../../util/index';
|
|
12
12
|
import { Logger } from '../../util/logger';
|
|
13
13
|
import { Security } from '../../util/security';
|
|
14
|
-
import type { ISecurity } from '../../util/security-registry';
|
|
15
14
|
export default class AMSSDK {
|
|
16
15
|
options: AMSCheckoutOptions;
|
|
17
16
|
originOptions: IoptionsParams;
|
|
@@ -38,20 +37,13 @@ export default class AMSSDK {
|
|
|
38
37
|
scene?: string;
|
|
39
38
|
}): void;
|
|
40
39
|
/**
|
|
41
|
-
* @description Obtain security SDK through scenario identification
|
|
42
|
-
* Handles three states: ready, loading, not found
|
|
40
|
+
* @description Obtain security SDK through scenario identification
|
|
43
41
|
*/
|
|
44
|
-
_getSecuritySDKByProductScene(securityConfig: InitSecurityConfig):
|
|
42
|
+
_getSecuritySDKByProductScene(securityConfig: InitSecurityConfig): Security;
|
|
45
43
|
/**
|
|
46
|
-
* @description
|
|
47
|
-
* Returns the Security instance even if currently loading
|
|
44
|
+
* @description New security SDK through scenario identification
|
|
48
45
|
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @description New security SDK through scenario identification (async-aware)
|
|
52
|
-
* Uses shared SecuritySdkRegistry and triggers ApdidLoader
|
|
53
|
-
*/
|
|
54
|
-
_newSecuritySDKByScene(securityConfig: InitSecurityConfig, successCallback?: () => void, failCallback?: (errMsg?: string) => void): void;
|
|
46
|
+
_newSecuritySDKByScene(securityConfig: InitSecurityConfig, successCallback?: () => void, failCallback?: (errMsg?: string) => void): Security;
|
|
55
47
|
/**
|
|
56
48
|
* @description Obtain risk control configuration in local storage
|
|
57
49
|
*/
|
|
@@ -28,9 +28,7 @@ import { EnvironmentEnum, modeEnum, networkModeEnum, osTypeEnum, ProductSceneEnu
|
|
|
28
28
|
import { checkTimeElapsed, device, EventCenter, getOrSetStorageId, getType, queryParse, safeJson } from "../../util/index";
|
|
29
29
|
import CallApp from "../../util/intl-callapp/es/main";
|
|
30
30
|
import { LogConfig, Logger } from "../../util/logger";
|
|
31
|
-
import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum
|
|
32
|
-
import { SecuritySdkRegistry } from "../../util/security-registry";
|
|
33
|
-
import { ApdidLoader } from "../../util/jshield-apdid";
|
|
31
|
+
import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum } from "../../util/security";
|
|
34
32
|
import { compareVersion } from "../../util/versionCompare";
|
|
35
33
|
import { BusManager, BusMessage } from "../bus";
|
|
36
34
|
import PreloadHelper from "../../foundation/utils/preload_helper";
|
|
@@ -168,44 +166,15 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
168
166
|
}, {
|
|
169
167
|
productScene: product
|
|
170
168
|
}).send();
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (registryEntry) {
|
|
178
|
-
if (registryEntry.status === 'ready') {
|
|
179
|
-
console.log('[web-sdk] skip init security sdk because it is already loaded');
|
|
180
|
-
this.logger.logInfo({
|
|
181
|
-
title: 'sdk_event_securitySdkPreInitSuccess'
|
|
182
|
-
}, {
|
|
183
|
-
productScene: product
|
|
184
|
-
}).send();
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (registryEntry.status === 'loading') {
|
|
188
|
-
console.log('[web-sdk] security sdk is already loading, waiting...');
|
|
189
|
-
registryEntry.loadingPromise.then(function () {
|
|
190
|
-
_this.logger.logInfo({
|
|
191
|
-
title: 'sdk_event_securitySdkPreInitSuccess'
|
|
192
|
-
}, {
|
|
193
|
-
productScene: product
|
|
194
|
-
}).send();
|
|
195
|
-
}).catch(function (err) {
|
|
196
|
-
_this.logger.logError({
|
|
197
|
-
title: 'sdk_error_securitySdkInitFailed',
|
|
198
|
-
msg: err === null || err === void 0 ? void 0 : err.message
|
|
199
|
-
}, {
|
|
200
|
-
productScene: product,
|
|
201
|
-
sign: 'Active initialization'
|
|
202
|
-
}).send();
|
|
203
|
-
});
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
169
|
+
var sdk = this._getSecuritySDKByProductScene({
|
|
170
|
+
product: product || scene
|
|
171
|
+
});
|
|
172
|
+
if (sdk) {
|
|
173
|
+
console.log('[web-sdk] skip init security sdk because it is already loaded');
|
|
174
|
+
return;
|
|
206
175
|
}
|
|
207
176
|
this._newSecuritySDKByScene({
|
|
208
|
-
product:
|
|
177
|
+
product: product || scene,
|
|
209
178
|
region: SecurityRegionEnum.SG
|
|
210
179
|
}, function () {
|
|
211
180
|
_this.logger.logInfo({
|
|
@@ -224,27 +193,13 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
224
193
|
});
|
|
225
194
|
}
|
|
226
195
|
/**
|
|
227
|
-
* @description Obtain security SDK through scenario identification
|
|
228
|
-
* Handles three states: ready, loading, not found
|
|
196
|
+
* @description Obtain security SDK through scenario identification
|
|
229
197
|
*/
|
|
230
198
|
}, {
|
|
231
199
|
key: "_getSecuritySDKByProductScene",
|
|
232
200
|
value: function _getSecuritySDKByProductScene(securityConfig) {
|
|
233
201
|
var storage = this.getSecurityConfigStorage(securityConfig.product);
|
|
234
202
|
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
235
|
-
|
|
236
|
-
// First check the shared registry (handles ready/loading/failed states)
|
|
237
|
-
var registryEntry = SecuritySdkRegistry.get(scene);
|
|
238
|
-
if (registryEntry) {
|
|
239
|
-
if (registryEntry.status === 'ready') {
|
|
240
|
-
return registryEntry.instance;
|
|
241
|
-
}
|
|
242
|
-
// Loading or failed - return undefined for backward compatibility
|
|
243
|
-
// Callers should use _awaitSecuritySDKByProductScene for async access
|
|
244
|
-
return undefined;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Fallback: check legacy map and preload helper
|
|
248
203
|
var securitySdk = this.securitySdkMap.get(scene);
|
|
249
204
|
if (!securitySdk) {
|
|
250
205
|
securitySdk = PreloadHelper.getSecuritySdk(scene);
|
|
@@ -255,105 +210,24 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
255
210
|
}
|
|
256
211
|
return securitySdk;
|
|
257
212
|
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @description Await security SDK by product scene (async)
|
|
261
|
-
* Returns the Security instance even if currently loading
|
|
262
|
-
*/
|
|
263
|
-
}, {
|
|
264
|
-
key: "_awaitSecuritySDKByProductScene",
|
|
265
|
-
value: (function () {
|
|
266
|
-
var _awaitSecuritySDKByProductScene2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(securityConfig) {
|
|
267
|
-
var storage, scene, instance;
|
|
268
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
269
|
-
while (1) switch (_context.prev = _context.next) {
|
|
270
|
-
case 0:
|
|
271
|
-
storage = this.getSecurityConfigStorage(securityConfig.product);
|
|
272
|
-
scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
273
|
-
_context.next = 4;
|
|
274
|
-
return SecuritySdkRegistry.getInstance(scene);
|
|
275
|
-
case 4:
|
|
276
|
-
instance = _context.sent;
|
|
277
|
-
return _context.abrupt("return", instance);
|
|
278
|
-
case 6:
|
|
279
|
-
case "end":
|
|
280
|
-
return _context.stop();
|
|
281
|
-
}
|
|
282
|
-
}, _callee, this);
|
|
283
|
-
}));
|
|
284
|
-
function _awaitSecuritySDKByProductScene(_x) {
|
|
285
|
-
return _awaitSecuritySDKByProductScene2.apply(this, arguments);
|
|
286
|
-
}
|
|
287
|
-
return _awaitSecuritySDKByProductScene;
|
|
288
|
-
}()
|
|
289
213
|
/**
|
|
290
|
-
* @description New security SDK through scenario identification
|
|
291
|
-
* Uses shared SecuritySdkRegistry and triggers ApdidLoader
|
|
214
|
+
* @description New security SDK through scenario identification
|
|
292
215
|
*/
|
|
293
|
-
)
|
|
294
216
|
}, {
|
|
295
217
|
key: "_newSecuritySDKByScene",
|
|
296
218
|
value: function _newSecuritySDKByScene(securityConfig, successCallback, failCallback) {
|
|
297
|
-
var _this$options2;
|
|
298
219
|
var storage = this.getSecurityConfigStorage(securityConfig.product);
|
|
299
220
|
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
300
221
|
var h5gateway = storage.h5gateway || getSecurityHost(securityConfig.region);
|
|
301
|
-
|
|
302
|
-
// Check if already exists in registry (avoid duplicates)
|
|
303
|
-
var existingEntry = SecuritySdkRegistry.get(scene);
|
|
304
|
-
if (existingEntry) {
|
|
305
|
-
if (existingEntry.status === 'ready') {
|
|
306
|
-
successCallback && successCallback();
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
if (existingEntry.status === 'loading') {
|
|
310
|
-
// Wait for existing loading to complete
|
|
311
|
-
existingEntry.loadingPromise.then(function () {
|
|
312
|
-
successCallback && successCallback();
|
|
313
|
-
}).catch(function (err) {
|
|
314
|
-
failCallback && failCallback(err === null || err === void 0 ? void 0 : err.message);
|
|
315
|
-
});
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
// failed status - allow retry by proceeding below
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// 非阻塞调度 ApdidLoader 加载,不阻塞 SDK 初始化
|
|
322
|
-
// Security 内部的 ensureApdidLoaded() 会在需要 token 时按需等待加载完成
|
|
323
|
-
var apdidEnv = mapEnvironment((_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.env) === null || _this$options2 === void 0 ? void 0 : _this$options2.environment);
|
|
324
|
-
var loader = ApdidLoader.getInstance();
|
|
325
|
-
loader.scheduleLoad({
|
|
326
|
-
environment: apdidEnv
|
|
327
|
-
});
|
|
328
222
|
try {
|
|
329
|
-
var _this$options3;
|
|
330
|
-
var environment = (_this$options3 = this.options) === null || _this$options3 === void 0 || (_this$options3 = _this$options3.env) === null || _this$options3 === void 0 ? void 0 : _this$options3.environment;
|
|
331
223
|
var securitySdk = new Security({
|
|
332
224
|
scene: scene,
|
|
333
|
-
h5gateway: h5gateway
|
|
334
|
-
environment: environment
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// Create loading promise and register in registry
|
|
338
|
-
var loadingPromise = new Promise(function (resolveLoading, rejectLoading) {
|
|
339
|
-
securitySdk.initSecurity(function () {
|
|
340
|
-
SecuritySdkRegistry.setReady(scene, securitySdk);
|
|
341
|
-
successCallback && successCallback();
|
|
342
|
-
resolveLoading(securitySdk);
|
|
343
|
-
}, function (msg) {
|
|
344
|
-
SecuritySdkRegistry.setFailed(scene, new Error(msg || 'Security init failed'));
|
|
345
|
-
failCallback && failCallback(msg);
|
|
346
|
-
rejectLoading(new Error(msg || 'Security init failed'));
|
|
347
|
-
});
|
|
225
|
+
h5gateway: h5gateway
|
|
348
226
|
});
|
|
349
|
-
|
|
350
|
-
// Register as loading in the shared registry
|
|
351
|
-
SecuritySdkRegistry.setLoading(scene, loadingPromise);
|
|
352
|
-
|
|
353
|
-
// Also keep reference in the legacy map for backward compatibility
|
|
354
227
|
this.securitySdkMap.set(scene, securitySdk);
|
|
228
|
+
securitySdk.initSecurity(successCallback, failCallback);
|
|
229
|
+
return securitySdk;
|
|
355
230
|
} catch (error) {
|
|
356
|
-
SecuritySdkRegistry.setFailed(scene, new Error(error === null || error === void 0 ? void 0 : error.toString()));
|
|
357
231
|
failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
|
|
358
232
|
}
|
|
359
233
|
}
|
|
@@ -459,17 +333,17 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
459
333
|
if (options !== null && options !== void 0 && options.onBeforeSubmit) {
|
|
460
334
|
if (typeof (options === null || options === void 0 ? void 0 : options.onBeforeSubmit) !== 'function') throw new Error(ERRORMESSAGE.INIT_PARAMETER_ERROR.EVENT_ERROR.message);
|
|
461
335
|
this._overrideSubscription(EVENT.beforeSubmit.name, /*#__PURE__*/function () {
|
|
462
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
336
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload) {
|
|
463
337
|
var eventCallbackId, res;
|
|
464
|
-
return _regeneratorRuntime().wrap(function
|
|
465
|
-
while (1) switch (
|
|
338
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
339
|
+
while (1) switch (_context.prev = _context.next) {
|
|
466
340
|
case 0:
|
|
467
341
|
eventCallbackId = uuid();
|
|
468
|
-
|
|
469
|
-
|
|
342
|
+
_context.prev = 1;
|
|
343
|
+
_context.next = 4;
|
|
470
344
|
return options.onBeforeSubmit(payload);
|
|
471
345
|
case 4:
|
|
472
|
-
res =
|
|
346
|
+
res = _context.sent;
|
|
473
347
|
_this2._componentApp.dispatchToApp({
|
|
474
348
|
context: {
|
|
475
349
|
event: EVENT.beforeSubmitDone.name,
|
|
@@ -477,11 +351,11 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
477
351
|
data: res
|
|
478
352
|
}
|
|
479
353
|
});
|
|
480
|
-
|
|
354
|
+
_context.next = 12;
|
|
481
355
|
break;
|
|
482
356
|
case 8:
|
|
483
|
-
|
|
484
|
-
|
|
357
|
+
_context.prev = 8;
|
|
358
|
+
_context.t0 = _context["catch"](1);
|
|
485
359
|
_this2._componentApp.dispatchToApp({
|
|
486
360
|
context: {
|
|
487
361
|
event: EVENT.beforeSubmitDone.name,
|
|
@@ -493,15 +367,15 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
493
367
|
});
|
|
494
368
|
_this2.logger.logError({
|
|
495
369
|
title: 'sdk_error_before_submit',
|
|
496
|
-
msg: JSON.stringify(
|
|
370
|
+
msg: JSON.stringify(_context.t0)
|
|
497
371
|
}).send();
|
|
498
372
|
case 12:
|
|
499
373
|
case "end":
|
|
500
|
-
return
|
|
374
|
+
return _context.stop();
|
|
501
375
|
}
|
|
502
|
-
},
|
|
376
|
+
}, _callee, null, [[1, 8]]);
|
|
503
377
|
}));
|
|
504
|
-
return function (
|
|
378
|
+
return function (_x) {
|
|
505
379
|
return _ref2.apply(this, arguments);
|
|
506
380
|
};
|
|
507
381
|
}(), EVENT.beforeSubmit.uniqueKey);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DeviceIdParameter, IoptionsParams } from '../../../types';
|
|
2
2
|
import { PaymentContext, SDKMetaData, Service } from '../../index';
|
|
3
|
+
import { Security } from './security';
|
|
3
4
|
export declare class SecurityService implements Service {
|
|
4
5
|
private logger;
|
|
5
6
|
private productScene;
|
|
6
|
-
|
|
7
|
+
static securitySdkMap: Map<string, Security>;
|
|
7
8
|
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
|
8
9
|
update(paymentContext: PaymentContext): void;
|
|
9
10
|
destroy(): void;
|
|
@@ -13,17 +14,11 @@ export declare class SecurityService implements Service {
|
|
|
13
14
|
private _initSecurity;
|
|
14
15
|
private logDeviceId;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
private _getSceneByProduct;
|
|
19
|
-
/**
|
|
20
|
-
* @description Obtain security SDK through scenario identification (async-aware)
|
|
21
|
-
* Handles three states: ready, loading, not found
|
|
17
|
+
* @description Obtain security SDK through scenario identification
|
|
22
18
|
*/
|
|
23
19
|
private _getSecuritySDKByProductScene;
|
|
24
20
|
/**
|
|
25
|
-
* @description New security SDK through scenario identification
|
|
26
|
-
* Uses shared SecuritySdkRegistry to avoid duplicate initialization
|
|
21
|
+
* @description New security SDK through scenario identification
|
|
27
22
|
*/
|
|
28
23
|
private _newSecuritySDKByScene;
|
|
29
24
|
/**
|