@alipay/ams-checkout 2.0.19 → 2.0.21
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/config/index.d.ts +7 -0
- package/esm/config/index.js +2 -2
- package/esm/constant/element.d.ts +2 -1
- package/esm/constant/element.js +1 -0
- package/esm/constant/index.d.ts +4 -21
- package/esm/core/component/ckp/index.d.ts +1 -1
- package/esm/core/component/ckp/index.js +5 -2
- package/esm/core/component/element/elementController/index.d.ts +3 -3
- package/esm/core/component/element/elementController/index.js +66 -42
- package/esm/core/component/element/elementProcessor/baseElementProcessor.d.ts +1 -0
- package/esm/core/component/element/elementProcessor/baseElementProcessor.js +1 -0
- package/esm/core/component/element/elementProcessor/convertPaymentMethods.d.ts +22 -0
- package/esm/core/component/element/elementProcessor/convertPaymentMethods.js +159 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +5 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +107 -29
- package/esm/core/component/element/index.d.ts +4 -1
- package/esm/core/component/element/index.js +19 -4
- package/esm/core/component/element/mock.js +2 -2
- package/esm/core/component/element/modernElementController/adapter.d.ts +19 -0
- package/esm/core/component/element/modernElementController/adapter.js +79 -0
- package/esm/core/component/element/modernElementController/index.d.ts +155 -0
- package/esm/core/component/element/modernElementController/index.js +1780 -0
- package/esm/core/component/element/type.d.ts +74 -19
- package/esm/core/component/element/util.d.ts +9 -2
- package/esm/core/component/element/util.js +3 -2
- package/esm/core/instance/index.d.ts +12 -4
- package/esm/core/instance/index.js +152 -26
- package/esm/foundation/service/event-center.js +1 -1
- package/esm/foundation/service/security/index.d.ts +9 -4
- package/esm/foundation/service/security/index.js +158 -35
- package/esm/foundation/service/security/security.d.ts +22 -1
- package/esm/foundation/service/security/security.js +150 -37
- package/esm/foundation/utils/preload_helper.d.ts +6 -3
- package/esm/foundation/utils/preload_helper.js +122 -32
- package/esm/main.js +4 -4
- package/esm/modern/global.d.ts +3 -0
- package/esm/modern/index.d.ts +5 -1
- package/esm/modern/index.js +1 -51
- package/esm/modern/tools.js +1 -0
- package/esm/plugin/component/channel.d.ts +2 -2
- package/esm/plugin/component/channel.js +18 -18
- package/esm/plugin/component/index.js +36 -29
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/types/index.d.ts +5 -1
- package/esm/util/beforeConfirm.d.ts +4 -2
- package/esm/util/beforeConfirm.js +15 -14
- package/esm/util/jshield-apdid/apdid-loader.js +377 -0
- package/esm/util/jshield-apdid/index.js +21 -0
- package/esm/util/logger.js +1 -2
- package/esm/util/security-registry.d.ts +72 -0
- package/esm/util/security-registry.js +175 -0
- package/esm/util/security.d.ts +22 -1
- package/esm/util/security.js +150 -39
- package/package.json +15 -9
- package/types.d.ts +843 -1103
- package/types.untrimmed.d.ts +995 -1122
- package/esm/modern/stageName.d.ts +0 -3
- package/esm/modern/stageName.js +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ShippingInfo } from "../../../modern/index";
|
|
1
2
|
import { ActionForm, ConnectErrorCode, IAmount, IAmountView, IMerchantAppointParam, IPaymentMethod } from '../../../types';
|
|
2
3
|
import AddressProcessor from './elementProcessor/addressProcessor';
|
|
3
4
|
import AuthProcessor from './elementProcessor/authProcessor';
|
|
@@ -149,7 +150,7 @@ type CompatibleVariables<T extends Record<string, string>> = {
|
|
|
149
150
|
export interface PaymentMountOptions extends BaseMountOptions {
|
|
150
151
|
type: ElementType.payment;
|
|
151
152
|
appearance?: {
|
|
152
|
-
theme?: ThemeType
|
|
153
|
+
theme?: ThemeType | `APR_${string}`;
|
|
153
154
|
layout?: {
|
|
154
155
|
type: PaymentElementLayout;
|
|
155
156
|
};
|
|
@@ -192,6 +193,54 @@ export interface PaymentMountOptions extends BaseMountOptions {
|
|
|
192
193
|
};
|
|
193
194
|
notRedirectAfterComplete?: boolean;
|
|
194
195
|
merchantAppointParam?: IMerchantAppointParam;
|
|
196
|
+
/**
|
|
197
|
+
* 支付方式配置
|
|
198
|
+
*
|
|
199
|
+
* 使用说明:
|
|
200
|
+
* - preview: true 时生效,用于配置预览展示的支付方式和外观
|
|
201
|
+
* - preview: false/undefined 时,此配置被忽略,支付方式来自后端 sdkAction.query 接口
|
|
202
|
+
*/
|
|
203
|
+
previewPaymentMethods?: {
|
|
204
|
+
/**
|
|
205
|
+
* 极速支付配置
|
|
206
|
+
*/
|
|
207
|
+
expressCheckout?: {
|
|
208
|
+
enabled: boolean;
|
|
209
|
+
methods?: {
|
|
210
|
+
/**
|
|
211
|
+
* 支付方式显示名称,如 "Apple Pay"
|
|
212
|
+
*/
|
|
213
|
+
paymentMethodName: string;
|
|
214
|
+
/**
|
|
215
|
+
* 支付方式类型,如 "APPLEPAY"
|
|
216
|
+
*/
|
|
217
|
+
paymentMethodType: string;
|
|
218
|
+
}[];
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* 支持的支付方式列表
|
|
222
|
+
* 数组顺序即为前端展示顺序
|
|
223
|
+
*/
|
|
224
|
+
supportedMethods?: {
|
|
225
|
+
/**
|
|
226
|
+
* 支付方式显示名称,如 "CARD", "AlipayHK"
|
|
227
|
+
*/
|
|
228
|
+
paymentMethodName: string;
|
|
229
|
+
/**
|
|
230
|
+
* 支付方式类型,如 "VISA", "ALIPAY_HK"
|
|
231
|
+
*/
|
|
232
|
+
paymentMethodType: string;
|
|
233
|
+
/**
|
|
234
|
+
* 支付方式图标 URL
|
|
235
|
+
*/
|
|
236
|
+
logoUrl?: string;
|
|
237
|
+
}[];
|
|
238
|
+
/**
|
|
239
|
+
* 推荐支付方式
|
|
240
|
+
* 值为 paymentMethodType,匹配的支付方式会被标记为 recommend
|
|
241
|
+
*/
|
|
242
|
+
topping?: string;
|
|
243
|
+
};
|
|
195
244
|
}
|
|
196
245
|
export declare enum AddressEventCallbackName {
|
|
197
246
|
SHIPPING_CHANGE = "SHIPPING_CHANGE"
|
|
@@ -244,23 +293,6 @@ export interface PaymentSubmitData {
|
|
|
244
293
|
paymentMethodId?: string;
|
|
245
294
|
};
|
|
246
295
|
}
|
|
247
|
-
export interface ShippingInfo {
|
|
248
|
-
shippingName: {
|
|
249
|
-
firstName: string;
|
|
250
|
-
lastName: string;
|
|
251
|
-
middleName?: string;
|
|
252
|
-
fullName?: string;
|
|
253
|
-
};
|
|
254
|
-
shippingPhoneNo: string;
|
|
255
|
-
shippingAddress: {
|
|
256
|
-
region: string;
|
|
257
|
-
address1: string;
|
|
258
|
-
address2: string;
|
|
259
|
-
city?: string;
|
|
260
|
-
state?: string;
|
|
261
|
-
zipCode: string;
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
296
|
export interface AddressSubmitData {
|
|
265
297
|
shippingName: {
|
|
266
298
|
firstName: string;
|
|
@@ -304,7 +336,8 @@ export interface SubmitFuncParams {
|
|
|
304
336
|
* - Only effective when payment method is Apple Pay
|
|
305
337
|
* - Invoked via event bridge after user FaceID/TouchID authorization on the payment sheet
|
|
306
338
|
* - Return true: proceed with charge
|
|
307
|
-
* - Return false /
|
|
339
|
+
* - Return false / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
|
|
340
|
+
* - Timeout: abort payment, returns MERCHANT_CONFIRM_TIMEOUT error code
|
|
308
341
|
*/
|
|
309
342
|
onBeforeConfirm?: () => Promise<boolean>;
|
|
310
343
|
}
|
|
@@ -441,6 +474,15 @@ export interface IElementOptions {
|
|
|
441
474
|
onStartLoading: () => void;
|
|
442
475
|
onEndLoading: () => void;
|
|
443
476
|
};
|
|
477
|
+
/**
|
|
478
|
+
* 预览模式开关
|
|
479
|
+
* - true / 'web': 跳过真实 API 请求,使用 mock 数据,按 WebElement(inline)方式渲染(向后兼容,等同于 'web')
|
|
480
|
+
* - 'mobile': 跳过真实 API 请求,使用 mock 数据,按 MobileElement(popup)方式渲染,用于 mobileElement 降级预览
|
|
481
|
+
* - false / undefined: 发起真实请求(默认行为)
|
|
482
|
+
*
|
|
483
|
+
* 使用场景:B 端配置后台预览,C 端生产环境不应使用
|
|
484
|
+
*/
|
|
485
|
+
preview?: boolean | 'web' | 'mobile';
|
|
444
486
|
}
|
|
445
487
|
export interface IElementProcessors {
|
|
446
488
|
[ElementType.auth]: AuthProcessor;
|
|
@@ -528,4 +570,17 @@ export interface EventDataMap {
|
|
|
528
570
|
[EVENTNAME.PAYMENTMETHODCHANGED]: PaymentMethodChangedData;
|
|
529
571
|
[EVENTNAME.BILLINGADDRESSCHANGED]: BillingAddressChangedData;
|
|
530
572
|
}
|
|
573
|
+
export interface IElementController {
|
|
574
|
+
mount(renderOptions: PaymentMountOptions, sdkSelector: string): Promise<ICommonApiResponse>;
|
|
575
|
+
submitPayment(params: SubmitFuncParams): Promise<IPaymentApiResponse>;
|
|
576
|
+
validateFields(): Promise<{
|
|
577
|
+
isValid: boolean;
|
|
578
|
+
}>;
|
|
579
|
+
/**
|
|
580
|
+
* @deprecated 不要使用,internal experiment方法
|
|
581
|
+
*/
|
|
582
|
+
updatePayment(paymentSessionData: string): Promise<boolean>;
|
|
583
|
+
destroy(): void;
|
|
584
|
+
on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
|
|
585
|
+
}
|
|
531
586
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IElementStatus } from '../../../foundation';
|
|
2
|
-
import { CashierSdkActionQueryResult, Ianalytics, IPaymentSessionMetaData } from '../../../types';
|
|
2
|
+
import { CashierSdkActionQueryResult, DisplayTypeEnum, Ianalytics, IPaymentSessionMetaData } from '../../../types';
|
|
3
3
|
import { ContainerController } from './elementContainerService/containerService';
|
|
4
4
|
import { ELEMENT_ENVIRONMENT_TYPE, EventCallbackCode, IElementOptions, IToastOptions } from './type';
|
|
5
5
|
export declare const formatElementOption: (options: IElementOptions) => {
|
|
@@ -19,6 +19,7 @@ export declare const formatElementOption: (options: IElementOptions) => {
|
|
|
19
19
|
onStartLoading: () => void;
|
|
20
20
|
onEndLoading: () => void;
|
|
21
21
|
};
|
|
22
|
+
preview?: boolean | "mobile" | "web";
|
|
22
23
|
};
|
|
23
24
|
export declare const validateElementOption: (options: IElementOptions) => {
|
|
24
25
|
isValid: boolean;
|
|
@@ -48,7 +49,7 @@ export declare function checkCanUpdate({ status, paymentContainerService, newPay
|
|
|
48
49
|
newPaymentSessionData: string;
|
|
49
50
|
oldPaymentSessionData: string;
|
|
50
51
|
}): boolean;
|
|
51
|
-
export declare function generateIframeSrc({ paymentSessionObj, paymentSession, instanceId, environment, appVersion, analytics, locale, pageUrl, link, }: {
|
|
52
|
+
export declare function generateIframeSrc({ paymentSessionObj, paymentSession, instanceId, environment, appVersion, analytics, locale, pageUrl, link, renderDisplayType, }: {
|
|
52
53
|
paymentSessionObj: IPaymentSessionMetaData;
|
|
53
54
|
paymentSession: string;
|
|
54
55
|
environment: string;
|
|
@@ -58,6 +59,12 @@ export declare function generateIframeSrc({ paymentSessionObj, paymentSession, i
|
|
|
58
59
|
pageUrl: string;
|
|
59
60
|
appVersion: string;
|
|
60
61
|
link?: string;
|
|
62
|
+
/**
|
|
63
|
+
* iframe 中 checkout-v2 的渲染形态。
|
|
64
|
+
* - inline(默认): WebElement 渲染
|
|
65
|
+
* - popup: MobileElement 渲染(用于 mobileElement 降级预览)
|
|
66
|
+
*/
|
|
67
|
+
renderDisplayType?: DisplayTypeEnum;
|
|
61
68
|
}): string;
|
|
62
69
|
export declare function handleRedirect(data: any, fromFastSdk: boolean, eventCallback: ({ code, message }: {
|
|
63
70
|
code: any;
|
|
@@ -138,7 +138,8 @@ export function generateIframeSrc(_ref3) {
|
|
|
138
138
|
analytics = _ref3.analytics,
|
|
139
139
|
locale = _ref3.locale,
|
|
140
140
|
pageUrl = _ref3.pageUrl,
|
|
141
|
-
link = _ref3.link
|
|
141
|
+
link = _ref3.link,
|
|
142
|
+
renderDisplayType = _ref3.renderDisplayType;
|
|
142
143
|
var componentSign = getComponentSign(paymentSessionObj);
|
|
143
144
|
var productSceneVersion = (paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$pa = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa === void 0 ? void 0 : _paymentSessionObj$pa.productSceneVersion) || '';
|
|
144
145
|
var productScene = (paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$pa2 = paymentSessionObj.paymentSessionConfig) === null || _paymentSessionObj$pa2 === void 0 ? void 0 : _paymentSessionObj$pa2.productScene) || '';
|
|
@@ -151,7 +152,7 @@ export function generateIframeSrc(_ref3) {
|
|
|
151
152
|
link = "".concat(baseUrl[_env]).concat(pageUrl);
|
|
152
153
|
}
|
|
153
154
|
var _getIframeUrl = getIframeUrl({
|
|
154
|
-
renderDisplayType: DisplayTypeEnum.inline,
|
|
155
|
+
renderDisplayType: renderDisplayType !== null && renderDisplayType !== void 0 ? renderDisplayType : DisplayTypeEnum.inline,
|
|
155
156
|
componentSign: componentSign,
|
|
156
157
|
analytics: analytics,
|
|
157
158
|
productScene: productScene,
|
|
@@ -11,6 +11,7 @@ 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';
|
|
14
15
|
export default class AMSSDK {
|
|
15
16
|
options: AMSCheckoutOptions;
|
|
16
17
|
originOptions: IoptionsParams;
|
|
@@ -37,13 +38,20 @@ export default class AMSSDK {
|
|
|
37
38
|
scene?: string;
|
|
38
39
|
}): void;
|
|
39
40
|
/**
|
|
40
|
-
* @description Obtain security SDK through scenario identification
|
|
41
|
+
* @description Obtain security SDK through scenario identification (async-aware)
|
|
42
|
+
* Handles three states: ready, loading, not found
|
|
41
43
|
*/
|
|
42
|
-
_getSecuritySDKByProductScene(securityConfig: InitSecurityConfig):
|
|
44
|
+
_getSecuritySDKByProductScene(securityConfig: InitSecurityConfig): ISecurity;
|
|
43
45
|
/**
|
|
44
|
-
* @description
|
|
46
|
+
* @description Await security SDK by product scene (async)
|
|
47
|
+
* Returns the Security instance even if currently loading
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
_awaitSecuritySDKByProductScene(securityConfig: InitSecurityConfig): Promise<Security | undefined>;
|
|
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;
|
|
47
55
|
/**
|
|
48
56
|
* @description Obtain risk control configuration in local storage
|
|
49
57
|
*/
|
|
@@ -28,7 +28,9 @@ 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 } from "../../util/security";
|
|
31
|
+
import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security, SecurityRegionEnum, mapEnvironment } from "../../util/security";
|
|
32
|
+
import { SecuritySdkRegistry } from "../../util/security-registry";
|
|
33
|
+
import { ApdidLoader } from "../../util/jshield-apdid";
|
|
32
34
|
import { compareVersion } from "../../util/versionCompare";
|
|
33
35
|
import { BusManager, BusMessage } from "../bus";
|
|
34
36
|
import PreloadHelper from "../../foundation/utils/preload_helper";
|
|
@@ -166,15 +168,44 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
166
168
|
}, {
|
|
167
169
|
productScene: product
|
|
168
170
|
}).send();
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
var effectiveProduct = product || scene;
|
|
172
|
+
var storage = this.getSecurityConfigStorage(effectiveProduct);
|
|
173
|
+
var securityScene = storage.scene || getSecurityScene(effectiveProduct);
|
|
174
|
+
|
|
175
|
+
// Check shared registry for all states
|
|
176
|
+
var registryEntry = SecuritySdkRegistry.get(securityScene);
|
|
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
|
+
}
|
|
175
206
|
}
|
|
176
207
|
this._newSecuritySDKByScene({
|
|
177
|
-
product:
|
|
208
|
+
product: effectiveProduct,
|
|
178
209
|
region: SecurityRegionEnum.SG
|
|
179
210
|
}, function () {
|
|
180
211
|
_this.logger.logInfo({
|
|
@@ -193,13 +224,27 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
193
224
|
});
|
|
194
225
|
}
|
|
195
226
|
/**
|
|
196
|
-
* @description Obtain security SDK through scenario identification
|
|
227
|
+
* @description Obtain security SDK through scenario identification (async-aware)
|
|
228
|
+
* Handles three states: ready, loading, not found
|
|
197
229
|
*/
|
|
198
230
|
}, {
|
|
199
231
|
key: "_getSecuritySDKByProductScene",
|
|
200
232
|
value: function _getSecuritySDKByProductScene(securityConfig) {
|
|
201
233
|
var storage = this.getSecurityConfigStorage(securityConfig.product);
|
|
202
234
|
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
|
|
203
248
|
var securitySdk = this.securitySdkMap.get(scene);
|
|
204
249
|
if (!securitySdk) {
|
|
205
250
|
securitySdk = PreloadHelper.getSecuritySdk(scene);
|
|
@@ -210,24 +255,105 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
210
255
|
}
|
|
211
256
|
return securitySdk;
|
|
212
257
|
}
|
|
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
|
+
}()
|
|
213
289
|
/**
|
|
214
|
-
* @description New security SDK through scenario identification
|
|
290
|
+
* @description New security SDK through scenario identification (async-aware)
|
|
291
|
+
* Uses shared SecuritySdkRegistry and triggers ApdidLoader
|
|
215
292
|
*/
|
|
293
|
+
)
|
|
216
294
|
}, {
|
|
217
295
|
key: "_newSecuritySDKByScene",
|
|
218
296
|
value: function _newSecuritySDKByScene(securityConfig, successCallback, failCallback) {
|
|
297
|
+
var _this$options2;
|
|
219
298
|
var storage = this.getSecurityConfigStorage(securityConfig.product);
|
|
220
299
|
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
221
300
|
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
|
+
});
|
|
222
328
|
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;
|
|
223
331
|
var securitySdk = new Security({
|
|
224
332
|
scene: scene,
|
|
225
|
-
h5gateway: h5gateway
|
|
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
|
+
});
|
|
226
348
|
});
|
|
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
|
|
227
354
|
this.securitySdkMap.set(scene, securitySdk);
|
|
228
|
-
securitySdk.initSecurity(successCallback, failCallback);
|
|
229
|
-
return securitySdk;
|
|
230
355
|
} catch (error) {
|
|
356
|
+
SecuritySdkRegistry.setFailed(scene, new Error(error === null || error === void 0 ? void 0 : error.toString()));
|
|
231
357
|
failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
|
|
232
358
|
}
|
|
233
359
|
}
|
|
@@ -333,17 +459,17 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
333
459
|
if (options !== null && options !== void 0 && options.onBeforeSubmit) {
|
|
334
460
|
if (typeof (options === null || options === void 0 ? void 0 : options.onBeforeSubmit) !== 'function') throw new Error(ERRORMESSAGE.INIT_PARAMETER_ERROR.EVENT_ERROR.message);
|
|
335
461
|
this._overrideSubscription(EVENT.beforeSubmit.name, /*#__PURE__*/function () {
|
|
336
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
462
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload) {
|
|
337
463
|
var eventCallbackId, res;
|
|
338
|
-
return _regeneratorRuntime().wrap(function
|
|
339
|
-
while (1) switch (
|
|
464
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
465
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
340
466
|
case 0:
|
|
341
467
|
eventCallbackId = uuid();
|
|
342
|
-
|
|
343
|
-
|
|
468
|
+
_context2.prev = 1;
|
|
469
|
+
_context2.next = 4;
|
|
344
470
|
return options.onBeforeSubmit(payload);
|
|
345
471
|
case 4:
|
|
346
|
-
res =
|
|
472
|
+
res = _context2.sent;
|
|
347
473
|
_this2._componentApp.dispatchToApp({
|
|
348
474
|
context: {
|
|
349
475
|
event: EVENT.beforeSubmitDone.name,
|
|
@@ -351,11 +477,11 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
351
477
|
data: res
|
|
352
478
|
}
|
|
353
479
|
});
|
|
354
|
-
|
|
480
|
+
_context2.next = 12;
|
|
355
481
|
break;
|
|
356
482
|
case 8:
|
|
357
|
-
|
|
358
|
-
|
|
483
|
+
_context2.prev = 8;
|
|
484
|
+
_context2.t0 = _context2["catch"](1);
|
|
359
485
|
_this2._componentApp.dispatchToApp({
|
|
360
486
|
context: {
|
|
361
487
|
event: EVENT.beforeSubmitDone.name,
|
|
@@ -367,15 +493,15 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
|
367
493
|
});
|
|
368
494
|
_this2.logger.logError({
|
|
369
495
|
title: 'sdk_error_before_submit',
|
|
370
|
-
msg: JSON.stringify(
|
|
496
|
+
msg: JSON.stringify(_context2.t0)
|
|
371
497
|
}).send();
|
|
372
498
|
case 12:
|
|
373
499
|
case "end":
|
|
374
|
-
return
|
|
500
|
+
return _context2.stop();
|
|
375
501
|
}
|
|
376
|
-
},
|
|
502
|
+
}, _callee2, null, [[1, 8]]);
|
|
377
503
|
}));
|
|
378
|
-
return function (
|
|
504
|
+
return function (_x2) {
|
|
379
505
|
return _ref2.apply(this, arguments);
|
|
380
506
|
};
|
|
381
507
|
}(), EVENT.beforeSubmit.uniqueKey);
|
|
@@ -103,7 +103,7 @@ export var EventCenter = /*#__PURE__*/function () {
|
|
|
103
103
|
if (!this.iframes.some(function (iframe) {
|
|
104
104
|
return iframe.origin === e.origin;
|
|
105
105
|
})) return;
|
|
106
|
-
if ((
|
|
106
|
+
if ((_e$data = e.data) !== null && _e$data !== void 0 && _e$data.source && ['react-devtools-content-script', 'react-devtools-backend-manager', 'react-devtools-bridge'].includes(e.data.source)) {
|
|
107
107
|
return; // Ignore messages from React DevTools
|
|
108
108
|
}
|
|
109
109
|
var isJson = isJsonString(e.data);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { DeviceIdParameter, IoptionsParams } from '../../../types';
|
|
2
2
|
import { PaymentContext, SDKMetaData, Service } from '../../index';
|
|
3
|
-
import { Security } from './security';
|
|
4
3
|
export declare class SecurityService implements Service {
|
|
5
4
|
private logger;
|
|
6
5
|
private productScene;
|
|
7
|
-
|
|
6
|
+
private environment?;
|
|
8
7
|
init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
|
|
9
8
|
update(paymentContext: PaymentContext): void;
|
|
10
9
|
destroy(): void;
|
|
@@ -14,11 +13,17 @@ export declare class SecurityService implements Service {
|
|
|
14
13
|
private _initSecurity;
|
|
15
14
|
private logDeviceId;
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* Get the scene string from product enum
|
|
17
|
+
*/
|
|
18
|
+
private _getSceneByProduct;
|
|
19
|
+
/**
|
|
20
|
+
* @description Obtain security SDK through scenario identification (async-aware)
|
|
21
|
+
* Handles three states: ready, loading, not found
|
|
18
22
|
*/
|
|
19
23
|
private _getSecuritySDKByProductScene;
|
|
20
24
|
/**
|
|
21
|
-
* @description New security SDK through scenario identification
|
|
25
|
+
* @description New security SDK through scenario identification (async)
|
|
26
|
+
* Uses shared SecuritySdkRegistry to avoid duplicate initialization
|
|
22
27
|
*/
|
|
23
28
|
private _newSecuritySDKByScene;
|
|
24
29
|
/**
|