@alipay/ams-checkout 0.0.1776306844-dev.2 → 0.0.1777017092-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/EventCenter/index.d.ts +10 -0
- package/esm/core/component/element/EventCenter/index.js +40 -4
- package/esm/core/component/element/elementController/index.d.ts +2 -0
- package/esm/core/component/element/elementController/index.js +29 -2
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +5 -0
- package/esm/core/instance/index.d.ts +12 -4
- package/esm/core/instance/index.js +152 -26
- 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 -36
- 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/index.js +1 -1
- package/esm/plugin/component/index.js +36 -29
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/util/jshield-apdid/apdid-loader.js +400 -0
- package/esm/util/jshield-apdid/index.js +21 -0
- 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 -36
- package/package.json +1 -1
- package/types.d.ts +4 -1
- package/types.untrimmed.d.ts +7 -1
|
@@ -9,20 +9,24 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
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
11
|
import { ProductSceneEnum } from "../../../types";
|
|
12
|
-
import { Security, SecurityRegionEnum, getSecurityConfigStorageKey, getSecurityHost, getSecurityScene } from "./security";
|
|
12
|
+
import { Security, SecurityRegionEnum, getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, mapEnvironment } from "./security";
|
|
13
13
|
import { getOrSetStorageId, safeJson } from "../../../util";
|
|
14
|
+
import { SecuritySdkRegistry } from "../../../util/security-registry";
|
|
15
|
+
import { ApdidLoader } from "../../../util/jshield-apdid";
|
|
14
16
|
import { ServiceProvider } from '..';
|
|
15
17
|
export var SecurityService = /*#__PURE__*/function () {
|
|
16
18
|
function SecurityService() {
|
|
17
19
|
_classCallCheck(this, SecurityService);
|
|
18
20
|
_defineProperty(this, "logger", void 0);
|
|
19
21
|
_defineProperty(this, "productScene", ProductSceneEnum.EASY_PAY);
|
|
22
|
+
_defineProperty(this, "environment", void 0);
|
|
20
23
|
}
|
|
21
24
|
_createClass(SecurityService, [{
|
|
22
25
|
key: "init",
|
|
23
26
|
value: function init(initOptions, instanceId, sdkMetaData) {
|
|
24
27
|
this.logger = ServiceProvider.getInstance(instanceId).getService('Log');
|
|
25
28
|
this.productScene = sdkMetaData.productScene;
|
|
29
|
+
this.environment = initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment;
|
|
26
30
|
}
|
|
27
31
|
}, {
|
|
28
32
|
key: "update",
|
|
@@ -46,40 +50,44 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
46
50
|
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
47
51
|
// To avoid rendering being blocked, move the logic to the next event loop for processing
|
|
48
52
|
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
49
|
-
var getDeviceIdStartTime, securitySDK, deviceId;
|
|
53
|
+
var getDeviceIdStartTime, product, securitySDK, deviceId;
|
|
50
54
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
51
55
|
while (1) switch (_context.prev = _context.next) {
|
|
52
56
|
case 0:
|
|
53
57
|
getDeviceIdStartTime = Date.now();
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
product = (deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.productScene) || _this.productScene;
|
|
59
|
+
_context.next = 4;
|
|
60
|
+
return _this._getSecuritySDKByProductScene({
|
|
61
|
+
product: product
|
|
56
62
|
});
|
|
63
|
+
case 4:
|
|
64
|
+
securitySDK = _context.sent;
|
|
57
65
|
deviceId = '';
|
|
58
66
|
if (!securitySDK) {
|
|
59
|
-
_context.next =
|
|
67
|
+
_context.next = 18;
|
|
60
68
|
break;
|
|
61
69
|
}
|
|
62
70
|
if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
|
|
63
|
-
_context.next =
|
|
71
|
+
_context.next = 13;
|
|
64
72
|
break;
|
|
65
73
|
}
|
|
66
|
-
_context.next =
|
|
74
|
+
_context.next = 10;
|
|
67
75
|
return securitySDK.pollingGetApdidToken(deviceIdParameter);
|
|
68
|
-
case
|
|
76
|
+
case 10:
|
|
69
77
|
_context.t0 = _context.sent;
|
|
70
|
-
_context.next =
|
|
78
|
+
_context.next = 16;
|
|
71
79
|
break;
|
|
72
|
-
case
|
|
73
|
-
_context.next =
|
|
80
|
+
case 13:
|
|
81
|
+
_context.next = 15;
|
|
74
82
|
return securitySDK.getApdidToken();
|
|
75
|
-
case
|
|
83
|
+
case 15:
|
|
76
84
|
_context.t0 = _context.sent;
|
|
77
|
-
case
|
|
85
|
+
case 16:
|
|
78
86
|
deviceId = _context.t0;
|
|
79
87
|
_this.logDeviceId(deviceId, getDeviceIdStartTime);
|
|
80
|
-
case
|
|
88
|
+
case 18:
|
|
81
89
|
resolve(deviceId);
|
|
82
|
-
case
|
|
90
|
+
case 19:
|
|
83
91
|
case "end":
|
|
84
92
|
return _context.stop();
|
|
85
93
|
}
|
|
@@ -145,6 +153,10 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
145
153
|
var isPre,
|
|
146
154
|
timeout,
|
|
147
155
|
sdkAction,
|
|
156
|
+
scene,
|
|
157
|
+
existing,
|
|
158
|
+
apdidEnv,
|
|
159
|
+
loader,
|
|
148
160
|
_args5 = arguments;
|
|
149
161
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
150
162
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -152,17 +164,78 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
152
164
|
isPre = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : false;
|
|
153
165
|
timeout = _args5.length > 1 ? _args5[1] : undefined;
|
|
154
166
|
sdkAction = isPre ? 'PreInit' : 'Init';
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_context5.next = 5;
|
|
167
|
+
scene = this._getSceneByProduct(this.productScene); // Check if already ready
|
|
168
|
+
if (!SecuritySdkRegistry.isReady(scene)) {
|
|
169
|
+
_context5.next = 6;
|
|
159
170
|
break;
|
|
160
171
|
}
|
|
161
172
|
return _context5.abrupt("return", Promise.resolve());
|
|
162
|
-
case
|
|
173
|
+
case 6:
|
|
174
|
+
if (!SecuritySdkRegistry.isLoading(scene)) {
|
|
175
|
+
_context5.next = 19;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
existing = SecuritySdkRegistry.get(scene);
|
|
179
|
+
if (!(existing && existing.status === 'loading')) {
|
|
180
|
+
_context5.next = 19;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
_context5.prev = 9;
|
|
184
|
+
_context5.next = 12;
|
|
185
|
+
return existing.loadingPromise;
|
|
186
|
+
case 12:
|
|
187
|
+
this.logger.logInfo({
|
|
188
|
+
title: "sdk_event_securitySdk".concat(sdkAction, "Success")
|
|
189
|
+
}).send();
|
|
190
|
+
_context5.next = 18;
|
|
191
|
+
break;
|
|
192
|
+
case 15:
|
|
193
|
+
_context5.prev = 15;
|
|
194
|
+
_context5.t0 = _context5["catch"](9);
|
|
195
|
+
this.logger.logError({
|
|
196
|
+
title: 'sdk_error_securitySdkInitFailed'
|
|
197
|
+
}, {
|
|
198
|
+
productScene: this.productScene,
|
|
199
|
+
sign: isPre ? 'Active initialization' : 'SDK internal initialization'
|
|
200
|
+
}).send();
|
|
201
|
+
case 18:
|
|
202
|
+
return _context5.abrupt("return");
|
|
203
|
+
case 19:
|
|
163
204
|
this.logger.logInfo({
|
|
164
205
|
title: "sdk_event_securitySdk".concat(sdkAction)
|
|
165
206
|
});
|
|
207
|
+
|
|
208
|
+
// 非阻塞调度 ApdidLoader 加载,在浏览器空闲时发起,2s 超时兜底
|
|
209
|
+
// Security 内部的 ensureApdidLoaded() 会在需要 token 时按需等待加载完成
|
|
210
|
+
apdidEnv = mapEnvironment(this.environment);
|
|
211
|
+
loader = ApdidLoader.getInstance();
|
|
212
|
+
loader.scheduleLoad({
|
|
213
|
+
environment: apdidEnv,
|
|
214
|
+
callbacks: {
|
|
215
|
+
onLoad: function onLoad(duration) {
|
|
216
|
+
_this2.logger.logInfo({
|
|
217
|
+
title: 'sdk_event_securitySdkScriptLoaded'
|
|
218
|
+
}, {
|
|
219
|
+
eventMessage: "".concat(duration)
|
|
220
|
+
}).send();
|
|
221
|
+
},
|
|
222
|
+
onLoadFailed: function onLoadFailed(error) {
|
|
223
|
+
_this2.logger.logError({
|
|
224
|
+
title: 'sdk_event_securitySdkLoadFailed',
|
|
225
|
+
msg: error.message
|
|
226
|
+
}, {
|
|
227
|
+
productScene: _this2.productScene
|
|
228
|
+
}).send();
|
|
229
|
+
},
|
|
230
|
+
onLoadTimeout: function onLoadTimeout() {
|
|
231
|
+
_this2.logger.logError({
|
|
232
|
+
title: 'sdk_event_securitySdkScriptLoadTimeout'
|
|
233
|
+
}, {
|
|
234
|
+
productScene: _this2.productScene
|
|
235
|
+
}).send();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
166
239
|
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
167
240
|
if (timeout) {
|
|
168
241
|
setTimeout(function () {
|
|
@@ -196,11 +269,11 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
196
269
|
reject();
|
|
197
270
|
});
|
|
198
271
|
}));
|
|
199
|
-
case
|
|
272
|
+
case 24:
|
|
200
273
|
case "end":
|
|
201
274
|
return _context5.stop();
|
|
202
275
|
}
|
|
203
|
-
}, _callee5, this);
|
|
276
|
+
}, _callee5, this, [[9, 15]]);
|
|
204
277
|
}));
|
|
205
278
|
function _initSecurity() {
|
|
206
279
|
return _initSecurity3.apply(this, arguments);
|
|
@@ -227,34 +300,85 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
227
300
|
}
|
|
228
301
|
|
|
229
302
|
/**
|
|
230
|
-
*
|
|
303
|
+
* Get the scene string from product enum
|
|
231
304
|
*/
|
|
232
305
|
}, {
|
|
233
|
-
key: "
|
|
234
|
-
value: function
|
|
235
|
-
var storage = this._getSecurityConfigStorage(
|
|
236
|
-
|
|
237
|
-
var securitySdk = SecurityService.securitySdkMap.get(scene);
|
|
238
|
-
return securitySdk;
|
|
306
|
+
key: "_getSceneByProduct",
|
|
307
|
+
value: function _getSceneByProduct(product) {
|
|
308
|
+
var storage = this._getSecurityConfigStorage(product);
|
|
309
|
+
return storage.scene || getSecurityScene(product);
|
|
239
310
|
}
|
|
240
311
|
|
|
241
312
|
/**
|
|
242
|
-
* @description
|
|
313
|
+
* @description Obtain security SDK through scenario identification (async-aware)
|
|
314
|
+
* Handles three states: ready, loading, not found
|
|
243
315
|
*/
|
|
316
|
+
}, {
|
|
317
|
+
key: "_getSecuritySDKByProductScene",
|
|
318
|
+
value: (function () {
|
|
319
|
+
var _getSecuritySDKByProductScene2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(securityConfig) {
|
|
320
|
+
var scene;
|
|
321
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
322
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
323
|
+
case 0:
|
|
324
|
+
scene = this._getSceneByProduct(securityConfig.product);
|
|
325
|
+
return _context6.abrupt("return", SecuritySdkRegistry.getInstance(scene));
|
|
326
|
+
case 2:
|
|
327
|
+
case "end":
|
|
328
|
+
return _context6.stop();
|
|
329
|
+
}
|
|
330
|
+
}, _callee6, this);
|
|
331
|
+
}));
|
|
332
|
+
function _getSecuritySDKByProductScene(_x3) {
|
|
333
|
+
return _getSecuritySDKByProductScene2.apply(this, arguments);
|
|
334
|
+
}
|
|
335
|
+
return _getSecuritySDKByProductScene;
|
|
336
|
+
}()
|
|
337
|
+
/**
|
|
338
|
+
* @description New security SDK through scenario identification (async)
|
|
339
|
+
* Uses shared SecuritySdkRegistry to avoid duplicate initialization
|
|
340
|
+
*/
|
|
341
|
+
)
|
|
244
342
|
}, {
|
|
245
343
|
key: "_newSecuritySDKByScene",
|
|
246
344
|
value: function _newSecuritySDKByScene(securityConfig, successCallback, failCallback) {
|
|
247
345
|
var storage = this._getSecurityConfigStorage(securityConfig.product);
|
|
248
346
|
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
249
347
|
var h5gateway = storage.h5gateway || getSecurityHost(securityConfig.region);
|
|
348
|
+
|
|
349
|
+
// Check if already exists in registry (avoid duplicates)
|
|
350
|
+
var existingEntry = SecuritySdkRegistry.get(scene);
|
|
351
|
+
if (existingEntry && (existingEntry.status === 'ready' || existingEntry.status === 'loading')) {
|
|
352
|
+
if (existingEntry.status === 'ready') {
|
|
353
|
+
successCallback && successCallback();
|
|
354
|
+
}
|
|
355
|
+
// If loading, the existing callbacks will handle it
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
250
358
|
try {
|
|
251
359
|
var securitySdk = new Security({
|
|
252
360
|
scene: scene,
|
|
253
|
-
h5gateway: h5gateway
|
|
361
|
+
h5gateway: h5gateway,
|
|
362
|
+
environment: this.environment
|
|
254
363
|
});
|
|
255
|
-
|
|
256
|
-
|
|
364
|
+
|
|
365
|
+
// Create loading promise and register in registry
|
|
366
|
+
var loadingPromise = new Promise(function (resolveLoading, rejectLoading) {
|
|
367
|
+
securitySdk.initSecurity(function () {
|
|
368
|
+
SecuritySdkRegistry.setReady(scene, securitySdk);
|
|
369
|
+
successCallback && successCallback();
|
|
370
|
+
resolveLoading(securitySdk);
|
|
371
|
+
}, function (msg) {
|
|
372
|
+
SecuritySdkRegistry.setFailed(scene, new Error(msg || 'Security init failed'));
|
|
373
|
+
failCallback && failCallback(msg);
|
|
374
|
+
rejectLoading(new Error(msg || 'Security init failed'));
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Register as loading in the shared registry
|
|
379
|
+
SecuritySdkRegistry.setLoading(scene, loadingPromise);
|
|
257
380
|
} catch (error) {
|
|
381
|
+
SecuritySdkRegistry.setFailed(scene, new Error(error === null || error === void 0 ? void 0 : error.toString()));
|
|
258
382
|
failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
|
|
259
383
|
}
|
|
260
384
|
}
|
|
@@ -280,5 +404,4 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
280
404
|
}
|
|
281
405
|
}]);
|
|
282
406
|
return SecurityService;
|
|
283
|
-
}();
|
|
284
|
-
_defineProperty(SecurityService, "securitySdkMap", new Map());
|
|
407
|
+
}();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IsecurityConfig, ProductSceneEnum, DeviceIdParameter } from '../../../types';
|
|
2
|
+
import type { ApdidEnvironment } from '../../../util/jshield-apdid';
|
|
2
3
|
export declare const getSecurityConfigStorageKey: (scene: ProductSceneEnum) => string;
|
|
3
4
|
export declare enum SecurityRegionEnum {
|
|
4
5
|
SG = "SG",
|
|
@@ -22,10 +23,30 @@ export declare const sceneMap: {
|
|
|
22
23
|
};
|
|
23
24
|
export declare const getSecurityHost: (region: string) => string;
|
|
24
25
|
export declare const getSecurityScene: (product: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Map SDK environment string to ApdidEnvironment for CDN URL selection.
|
|
28
|
+
*/
|
|
29
|
+
export declare const mapEnvironment: (env?: string) => ApdidEnvironment;
|
|
25
30
|
export declare class Security {
|
|
26
31
|
scene: string;
|
|
27
32
|
h5gateway: string;
|
|
28
|
-
|
|
33
|
+
private environment?;
|
|
34
|
+
private apdidLoaded;
|
|
35
|
+
private apdidLoadFailed;
|
|
36
|
+
constructor(options: IsecurityConfig & {
|
|
37
|
+
environment?: string;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Ensure the apdid-core script is loaded async.
|
|
41
|
+
* Returns true if loaded successfully, false otherwise.
|
|
42
|
+
* On failure, sets apdidLoadFailed flag for graceful degradation.
|
|
43
|
+
*/
|
|
44
|
+
private ensureApdidLoaded;
|
|
45
|
+
/**
|
|
46
|
+
* Get the APDID module from the loader.
|
|
47
|
+
* Returns undefined if not loaded.
|
|
48
|
+
*/
|
|
49
|
+
private getAPDIDModule;
|
|
29
50
|
initSecurity(successCallback: any, failCallback: any): void;
|
|
30
51
|
private initToken;
|
|
31
52
|
pollingGetApdidToken(config?: DeviceIdParameter): Promise<string>;
|
|
@@ -9,7 +9,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
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
11
|
import { ProductSceneEnum } from "../../../types";
|
|
12
|
-
import
|
|
12
|
+
import { ApdidLoader } from "../../../util/jshield-apdid";
|
|
13
13
|
export var getSecurityConfigStorageKey = function getSecurityConfigStorageKey(scene) {
|
|
14
14
|
return "AMSSDK_SECURITY_CONFIG_".concat(scene);
|
|
15
15
|
};
|
|
@@ -31,17 +31,108 @@ export var getSecurityHost = function getSecurityHost(region) {
|
|
|
31
31
|
export var getSecurityScene = function getSecurityScene(product) {
|
|
32
32
|
return sceneMap[product] || '';
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Map SDK environment string to ApdidEnvironment for CDN URL selection.
|
|
37
|
+
*/
|
|
38
|
+
export var mapEnvironment = function mapEnvironment(env) {
|
|
39
|
+
if (!env) return 'production';
|
|
40
|
+
var lower = env.toLowerCase();
|
|
41
|
+
if (lower === 'pre' || lower === 'light_sandbox') return 'pre';
|
|
42
|
+
if (lower === 'dev' || lower === 'test' || lower === 'local') return 'dev';
|
|
43
|
+
return 'production';
|
|
44
|
+
};
|
|
34
45
|
export var Security = /*#__PURE__*/function () {
|
|
35
46
|
function Security(options) {
|
|
36
47
|
_classCallCheck(this, Security);
|
|
37
48
|
_defineProperty(this, "scene", void 0);
|
|
38
49
|
_defineProperty(this, "h5gateway", void 0);
|
|
50
|
+
_defineProperty(this, "environment", void 0);
|
|
51
|
+
_defineProperty(this, "apdidLoaded", false);
|
|
52
|
+
_defineProperty(this, "apdidLoadFailed", false);
|
|
39
53
|
this.scene = options.scene;
|
|
40
54
|
this.h5gateway = options.h5gateway || securityHost[SecurityRegionEnum.SG];
|
|
55
|
+
this.environment = options.environment;
|
|
41
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Ensure the apdid-core script is loaded async.
|
|
60
|
+
* Returns true if loaded successfully, false otherwise.
|
|
61
|
+
* On failure, sets apdidLoadFailed flag for graceful degradation.
|
|
62
|
+
*/
|
|
42
63
|
_createClass(Security, [{
|
|
64
|
+
key: "ensureApdidLoaded",
|
|
65
|
+
value: (function () {
|
|
66
|
+
var _ensureApdidLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
67
|
+
var loader, apdidEnv;
|
|
68
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
69
|
+
while (1) switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!this.apdidLoaded) {
|
|
72
|
+
_context.next = 2;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return _context.abrupt("return", true);
|
|
76
|
+
case 2:
|
|
77
|
+
if (!this.apdidLoadFailed) {
|
|
78
|
+
_context.next = 4;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return _context.abrupt("return", false);
|
|
82
|
+
case 4:
|
|
83
|
+
loader = ApdidLoader.getInstance();
|
|
84
|
+
apdidEnv = mapEnvironment(this.environment);
|
|
85
|
+
_context.prev = 6;
|
|
86
|
+
_context.next = 9;
|
|
87
|
+
return loader.load({
|
|
88
|
+
environment: apdidEnv,
|
|
89
|
+
callbacks: {
|
|
90
|
+
onLoad: function onLoad(duration) {
|
|
91
|
+
console.log("[Security] apdid-core script loaded in ".concat(duration, "ms"));
|
|
92
|
+
},
|
|
93
|
+
onLoadFailed: function onLoadFailed(error) {
|
|
94
|
+
console.error('[Security] apdid-core script load failed:', error.message);
|
|
95
|
+
},
|
|
96
|
+
onLoadTimeout: function onLoadTimeout() {
|
|
97
|
+
console.error('[Security] apdid-core script load timeout');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
case 9:
|
|
102
|
+
this.apdidLoaded = true;
|
|
103
|
+
return _context.abrupt("return", true);
|
|
104
|
+
case 13:
|
|
105
|
+
_context.prev = 13;
|
|
106
|
+
_context.t0 = _context["catch"](6);
|
|
107
|
+
console.error('[Security] apdid-core load error, degrading:', _context.t0);
|
|
108
|
+
this.apdidLoadFailed = true;
|
|
109
|
+
return _context.abrupt("return", false);
|
|
110
|
+
case 18:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee, this, [[6, 13]]);
|
|
115
|
+
}));
|
|
116
|
+
function ensureApdidLoaded() {
|
|
117
|
+
return _ensureApdidLoaded.apply(this, arguments);
|
|
118
|
+
}
|
|
119
|
+
return ensureApdidLoaded;
|
|
120
|
+
}()
|
|
121
|
+
/**
|
|
122
|
+
* Get the APDID module from the loader.
|
|
123
|
+
* Returns undefined if not loaded.
|
|
124
|
+
*/
|
|
125
|
+
)
|
|
126
|
+
}, {
|
|
127
|
+
key: "getAPDIDModule",
|
|
128
|
+
value: function getAPDIDModule() {
|
|
129
|
+
var loader = ApdidLoader.getInstance();
|
|
130
|
+
return loader.getApdidModule();
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
43
133
|
key: "initSecurity",
|
|
44
134
|
value: function initSecurity(successCallback, failCallback) {
|
|
135
|
+
var _this = this;
|
|
45
136
|
if (!this.scene) {
|
|
46
137
|
throw new Error('securityConfig parameter error');
|
|
47
138
|
}
|
|
@@ -50,12 +141,23 @@ export var Security = /*#__PURE__*/function () {
|
|
|
50
141
|
console.error(errorMsg);
|
|
51
142
|
throw new Error(errorMsg);
|
|
52
143
|
}
|
|
53
|
-
|
|
144
|
+
|
|
145
|
+
// Async: ensure script is loaded before calling initToken
|
|
146
|
+
this.ensureApdidLoaded().then(function (loaded) {
|
|
147
|
+
if (!loaded) {
|
|
148
|
+
failCallback && failCallback('apdid-core script load failed');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
_this.initToken(successCallback, failCallback);
|
|
152
|
+
}).catch(function () {
|
|
153
|
+
failCallback && failCallback('apdid-core script load failed');
|
|
154
|
+
});
|
|
54
155
|
}
|
|
55
156
|
}, {
|
|
56
157
|
key: "initToken",
|
|
57
158
|
value: function initToken(successCallback, failCallback) {
|
|
58
159
|
try {
|
|
160
|
+
var APDID = this.getAPDIDModule();
|
|
59
161
|
APDID === null || APDID === void 0 || APDID.initToken(this.scene, {
|
|
60
162
|
host: this.h5gateway
|
|
61
163
|
}, function (success, tokenResult, msg) {
|
|
@@ -73,48 +175,48 @@ export var Security = /*#__PURE__*/function () {
|
|
|
73
175
|
}, {
|
|
74
176
|
key: "pollingGetApdidToken",
|
|
75
177
|
value: function () {
|
|
76
|
-
var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
77
|
-
var
|
|
178
|
+
var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
|
|
179
|
+
var _this2 = this;
|
|
78
180
|
var tokenCollectTime, dataPollingInterval, asyncFunc;
|
|
79
|
-
return _regeneratorRuntime().wrap(function
|
|
80
|
-
while (1) switch (
|
|
181
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
182
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
81
183
|
case 0:
|
|
82
184
|
tokenCollectTime = parseInt((config === null || config === void 0 ? void 0 : config.tokenCollectTime) || '0', 10);
|
|
83
185
|
dataPollingInterval = parseInt((config === null || config === void 0 ? void 0 : config.dataPollingInterval) || '500', 10);
|
|
84
186
|
asyncFunc = /*#__PURE__*/function () {
|
|
85
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
187
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
86
188
|
var deviceId, interval, polling;
|
|
87
|
-
return _regeneratorRuntime().wrap(function
|
|
88
|
-
while (1) switch (
|
|
189
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
190
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
89
191
|
case 0:
|
|
90
|
-
|
|
91
|
-
return
|
|
192
|
+
_context3.next = 2;
|
|
193
|
+
return _this2.getApdidToken();
|
|
92
194
|
case 2:
|
|
93
|
-
deviceId =
|
|
195
|
+
deviceId = _context3.sent;
|
|
94
196
|
if (!deviceId) {
|
|
95
|
-
|
|
197
|
+
_context3.next = 5;
|
|
96
198
|
break;
|
|
97
199
|
}
|
|
98
|
-
return
|
|
200
|
+
return _context3.abrupt("return", resolve(deviceId));
|
|
99
201
|
case 5:
|
|
100
202
|
polling = /*#__PURE__*/function () {
|
|
101
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
102
|
-
return _regeneratorRuntime().wrap(function
|
|
103
|
-
while (1) switch (
|
|
203
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
205
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
104
206
|
case 0:
|
|
105
|
-
|
|
106
|
-
return
|
|
207
|
+
_context2.next = 2;
|
|
208
|
+
return _this2.getApdidToken();
|
|
107
209
|
case 2:
|
|
108
|
-
deviceId =
|
|
210
|
+
deviceId = _context2.sent;
|
|
109
211
|
if (deviceId) {
|
|
110
212
|
clearInterval(interval);
|
|
111
213
|
resolve(deviceId);
|
|
112
214
|
}
|
|
113
215
|
case 4:
|
|
114
216
|
case "end":
|
|
115
|
-
return
|
|
217
|
+
return _context2.stop();
|
|
116
218
|
}
|
|
117
|
-
},
|
|
219
|
+
}, _callee2);
|
|
118
220
|
}));
|
|
119
221
|
return function polling() {
|
|
120
222
|
return _ref2.apply(this, arguments);
|
|
@@ -127,22 +229,22 @@ export var Security = /*#__PURE__*/function () {
|
|
|
127
229
|
}, tokenCollectTime);
|
|
128
230
|
case 8:
|
|
129
231
|
case "end":
|
|
130
|
-
return
|
|
232
|
+
return _context3.stop();
|
|
131
233
|
}
|
|
132
|
-
},
|
|
234
|
+
}, _callee3);
|
|
133
235
|
}));
|
|
134
236
|
return function asyncFunc(_x2) {
|
|
135
237
|
return _ref.apply(this, arguments);
|
|
136
238
|
};
|
|
137
239
|
}();
|
|
138
|
-
return
|
|
240
|
+
return _context4.abrupt("return", new Promise(function (resolve) {
|
|
139
241
|
asyncFunc(resolve);
|
|
140
242
|
}));
|
|
141
243
|
case 4:
|
|
142
244
|
case "end":
|
|
143
|
-
return
|
|
245
|
+
return _context4.stop();
|
|
144
246
|
}
|
|
145
|
-
},
|
|
247
|
+
}, _callee4);
|
|
146
248
|
}));
|
|
147
249
|
function pollingGetApdidToken(_x) {
|
|
148
250
|
return _pollingGetApdidToken.apply(this, arguments);
|
|
@@ -152,25 +254,37 @@ export var Security = /*#__PURE__*/function () {
|
|
|
152
254
|
}, {
|
|
153
255
|
key: "getApdidToken",
|
|
154
256
|
value: function () {
|
|
155
|
-
var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
|
|
257
|
+
var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
258
|
+
var _this3 = this;
|
|
259
|
+
var loaded;
|
|
260
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
261
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
159
262
|
case 0:
|
|
160
|
-
|
|
263
|
+
_context5.next = 2;
|
|
264
|
+
return this.ensureApdidLoaded();
|
|
265
|
+
case 2:
|
|
266
|
+
loaded = _context5.sent;
|
|
267
|
+
if (loaded) {
|
|
268
|
+
_context5.next = 5;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
return _context5.abrupt("return", '');
|
|
272
|
+
case 5:
|
|
273
|
+
return _context5.abrupt("return", new Promise(function (resolve) {
|
|
161
274
|
try {
|
|
162
|
-
|
|
275
|
+
var APDID = _this3.getAPDIDModule();
|
|
276
|
+
APDID === null || APDID === void 0 || APDID.getApdidToken(_this3.scene, function (tokenResult) {
|
|
163
277
|
resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
|
|
164
278
|
});
|
|
165
279
|
} catch (error) {
|
|
166
280
|
resolve('');
|
|
167
281
|
}
|
|
168
282
|
}));
|
|
169
|
-
case
|
|
283
|
+
case 6:
|
|
170
284
|
case "end":
|
|
171
|
-
return
|
|
285
|
+
return _context5.stop();
|
|
172
286
|
}
|
|
173
|
-
},
|
|
287
|
+
}, _callee5, this);
|
|
174
288
|
}));
|
|
175
289
|
function getApdidToken() {
|
|
176
290
|
return _getApdidToken.apply(this, arguments);
|
|
@@ -3,10 +3,13 @@ import { Security } from '../../util/security';
|
|
|
3
3
|
export default class PreloadHelper {
|
|
4
4
|
static isWebAppPreloaded: boolean;
|
|
5
5
|
static isSecuritySDKPreloaded: boolean;
|
|
6
|
-
private static securitySdkMap;
|
|
7
6
|
static preloadWebApp(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment?: string, useV2?: boolean): void;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Preload security SDK asynchronously.
|
|
9
|
+
* Triggers ApdidLoader.load() for async script loading and registers in SecuritySdkRegistry.
|
|
10
|
+
*/
|
|
11
|
+
static preloadSecuritySDK(product: ProductSceneEnum, securityRegion?: string, environment?: string): Promise<void>;
|
|
12
|
+
static getSecuritySdk(scene: string): Security | undefined;
|
|
10
13
|
static buildWebAppPreloadUrl(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment: string, useV2?: boolean): {
|
|
11
14
|
preloadUrl: string;
|
|
12
15
|
containerId: string;
|