@alipay/ams-checkout 0.0.1783663570-dev.6 → 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 -4
- package/dist/ams-checkout.min.js +1 -2
- package/esm/config/index.d.ts +0 -7
- package/esm/config/index.js +2 -2
- package/esm/constant/element.d.ts +1 -2
- package/esm/constant/element.js +0 -1
- package/esm/constant/index.d.ts +21 -4
- package/esm/core/component/element/elementController/index.d.ts +3 -3
- 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/index.d.ts +1 -4
- package/esm/core/component/element/index.js +4 -19
- package/esm/core/component/element/type.d.ts +18 -16
- package/esm/core/instance/index.d.ts +4 -12
- package/esm/core/instance/index.js +26 -152
- package/esm/foundation/service/event-center.js +1 -1
- 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.d.ts +1 -5
- package/esm/modern/index.js +51 -1
- package/esm/modern/stageName.d.ts +3 -0
- package/esm/modern/stageName.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 +29 -36
- package/esm/types/index.d.ts +0 -1
- package/esm/util/beforeConfirm.d.ts +2 -4
- package/esm/util/beforeConfirm.js +14 -15
- package/esm/util/logger.js +2 -1
- package/esm/util/security.d.ts +1 -22
- package/esm/util/security.js +39 -150
- package/package.json +9 -15
- package/types.d.ts +94 -785
- package/types.untrimmed.d.ts +108 -929
- package/dist/ams-checkout.min.js.map +0 -1
- package/esm/core/component/element/modernElementController/adapter.d.ts +0 -19
- package/esm/core/component/element/modernElementController/adapter.js +0 -73
- package/esm/core/component/element/modernElementController/index.d.ts +0 -149
- package/esm/core/component/element/modernElementController/index.js +0 -1665
- package/esm/modern/global.d.ts +0 -3
- package/esm/modern/tools.js +0 -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
|
@@ -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);
|
|
@@ -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 ((_e$data = e.data)
|
|
106
|
+
if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
|
|
107
107
|
return; // Ignore messages from React DevTools
|
|
108
108
|
}
|
|
109
109
|
var isJson = isJsonString(e.data);
|
|
@@ -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
|
/**
|
|
@@ -9,24 +9,20 @@ 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
|
|
12
|
+
import { Security, SecurityRegionEnum, getSecurityConfigStorageKey, getSecurityHost, getSecurityScene } from "./security";
|
|
13
13
|
import { getOrSetStorageId, safeJson } from "../../../util";
|
|
14
|
-
import { SecuritySdkRegistry } from "../../../util/security-registry";
|
|
15
|
-
import { ApdidLoader } from "../../../util/jshield-apdid";
|
|
16
14
|
import { ServiceProvider } from '..';
|
|
17
15
|
export var SecurityService = /*#__PURE__*/function () {
|
|
18
16
|
function SecurityService() {
|
|
19
17
|
_classCallCheck(this, SecurityService);
|
|
20
18
|
_defineProperty(this, "logger", void 0);
|
|
21
19
|
_defineProperty(this, "productScene", ProductSceneEnum.EASY_PAY);
|
|
22
|
-
_defineProperty(this, "environment", void 0);
|
|
23
20
|
}
|
|
24
21
|
_createClass(SecurityService, [{
|
|
25
22
|
key: "init",
|
|
26
23
|
value: function init(initOptions, instanceId, sdkMetaData) {
|
|
27
24
|
this.logger = ServiceProvider.getInstance(instanceId).getService('Log');
|
|
28
25
|
this.productScene = sdkMetaData.productScene;
|
|
29
|
-
this.environment = initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment;
|
|
30
26
|
}
|
|
31
27
|
}, {
|
|
32
28
|
key: "update",
|
|
@@ -50,44 +46,40 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
50
46
|
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
51
47
|
// To avoid rendering being blocked, move the logic to the next event loop for processing
|
|
52
48
|
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
53
|
-
var getDeviceIdStartTime,
|
|
49
|
+
var getDeviceIdStartTime, securitySDK, deviceId;
|
|
54
50
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
55
51
|
while (1) switch (_context.prev = _context.next) {
|
|
56
52
|
case 0:
|
|
57
53
|
getDeviceIdStartTime = Date.now();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return _this._getSecuritySDKByProductScene({
|
|
61
|
-
product: product
|
|
54
|
+
securitySDK = _this._getSecuritySDKByProductScene({
|
|
55
|
+
product: (deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.productScene) || _this.productScene
|
|
62
56
|
});
|
|
63
|
-
case 4:
|
|
64
|
-
securitySDK = _context.sent;
|
|
65
57
|
deviceId = '';
|
|
66
58
|
if (!securitySDK) {
|
|
67
|
-
_context.next =
|
|
59
|
+
_context.next = 15;
|
|
68
60
|
break;
|
|
69
61
|
}
|
|
70
62
|
if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
|
|
71
|
-
_context.next =
|
|
63
|
+
_context.next = 10;
|
|
72
64
|
break;
|
|
73
65
|
}
|
|
74
|
-
_context.next =
|
|
66
|
+
_context.next = 7;
|
|
75
67
|
return securitySDK.pollingGetApdidToken(deviceIdParameter);
|
|
76
|
-
case
|
|
68
|
+
case 7:
|
|
77
69
|
_context.t0 = _context.sent;
|
|
78
|
-
_context.next =
|
|
70
|
+
_context.next = 13;
|
|
79
71
|
break;
|
|
80
|
-
case
|
|
81
|
-
_context.next =
|
|
72
|
+
case 10:
|
|
73
|
+
_context.next = 12;
|
|
82
74
|
return securitySDK.getApdidToken();
|
|
83
|
-
case
|
|
75
|
+
case 12:
|
|
84
76
|
_context.t0 = _context.sent;
|
|
85
|
-
case
|
|
77
|
+
case 13:
|
|
86
78
|
deviceId = _context.t0;
|
|
87
79
|
_this.logDeviceId(deviceId, getDeviceIdStartTime);
|
|
88
|
-
case
|
|
80
|
+
case 15:
|
|
89
81
|
resolve(deviceId);
|
|
90
|
-
case
|
|
82
|
+
case 16:
|
|
91
83
|
case "end":
|
|
92
84
|
return _context.stop();
|
|
93
85
|
}
|
|
@@ -153,10 +145,6 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
153
145
|
var isPre,
|
|
154
146
|
timeout,
|
|
155
147
|
sdkAction,
|
|
156
|
-
scene,
|
|
157
|
-
existing,
|
|
158
|
-
apdidEnv,
|
|
159
|
-
loader,
|
|
160
148
|
_args5 = arguments;
|
|
161
149
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
162
150
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -164,78 +152,17 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
164
152
|
isPre = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : false;
|
|
165
153
|
timeout = _args5.length > 1 ? _args5[1] : undefined;
|
|
166
154
|
sdkAction = isPre ? 'PreInit' : 'Init';
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
if (!this._getSecuritySDKByProductScene({
|
|
156
|
+
product: this.productScene
|
|
157
|
+
})) {
|
|
158
|
+
_context5.next = 5;
|
|
170
159
|
break;
|
|
171
160
|
}
|
|
172
161
|
return _context5.abrupt("return", Promise.resolve());
|
|
173
|
-
case
|
|
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:
|
|
162
|
+
case 5:
|
|
204
163
|
this.logger.logInfo({
|
|
205
164
|
title: "sdk_event_securitySdk".concat(sdkAction)
|
|
206
165
|
});
|
|
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
|
-
});
|
|
239
166
|
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
240
167
|
if (timeout) {
|
|
241
168
|
setTimeout(function () {
|
|
@@ -269,11 +196,11 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
269
196
|
reject();
|
|
270
197
|
});
|
|
271
198
|
}));
|
|
272
|
-
case
|
|
199
|
+
case 7:
|
|
273
200
|
case "end":
|
|
274
201
|
return _context5.stop();
|
|
275
202
|
}
|
|
276
|
-
}, _callee5, this
|
|
203
|
+
}, _callee5, this);
|
|
277
204
|
}));
|
|
278
205
|
function _initSecurity() {
|
|
279
206
|
return _initSecurity3.apply(this, arguments);
|
|
@@ -300,85 +227,34 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
300
227
|
}
|
|
301
228
|
|
|
302
229
|
/**
|
|
303
|
-
*
|
|
230
|
+
* @description Obtain security SDK through scenario identification
|
|
304
231
|
*/
|
|
305
232
|
}, {
|
|
306
|
-
key: "
|
|
307
|
-
value: function
|
|
308
|
-
var storage = this._getSecurityConfigStorage(product);
|
|
309
|
-
|
|
233
|
+
key: "_getSecuritySDKByProductScene",
|
|
234
|
+
value: function _getSecuritySDKByProductScene(securityConfig) {
|
|
235
|
+
var storage = this._getSecurityConfigStorage(securityConfig.product);
|
|
236
|
+
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
237
|
+
var securitySdk = SecurityService.securitySdkMap.get(scene);
|
|
238
|
+
return securitySdk;
|
|
310
239
|
}
|
|
311
240
|
|
|
312
241
|
/**
|
|
313
|
-
* @description
|
|
314
|
-
* Handles three states: ready, loading, not found
|
|
242
|
+
* @description New security SDK through scenario identification
|
|
315
243
|
*/
|
|
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
|
-
)
|
|
342
244
|
}, {
|
|
343
245
|
key: "_newSecuritySDKByScene",
|
|
344
246
|
value: function _newSecuritySDKByScene(securityConfig, successCallback, failCallback) {
|
|
345
247
|
var storage = this._getSecurityConfigStorage(securityConfig.product);
|
|
346
248
|
var scene = storage.scene || getSecurityScene(securityConfig.product);
|
|
347
249
|
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
|
-
}
|
|
358
250
|
try {
|
|
359
251
|
var securitySdk = new Security({
|
|
360
252
|
scene: scene,
|
|
361
|
-
h5gateway: h5gateway
|
|
362
|
-
environment: this.environment
|
|
253
|
+
h5gateway: h5gateway
|
|
363
254
|
});
|
|
364
|
-
|
|
365
|
-
|
|
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);
|
|
255
|
+
SecurityService.securitySdkMap.set(scene, securitySdk);
|
|
256
|
+
securitySdk.initSecurity(successCallback, failCallback);
|
|
380
257
|
} catch (error) {
|
|
381
|
-
SecuritySdkRegistry.setFailed(scene, new Error(error === null || error === void 0 ? void 0 : error.toString()));
|
|
382
258
|
failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
|
|
383
259
|
}
|
|
384
260
|
}
|
|
@@ -404,4 +280,5 @@ export var SecurityService = /*#__PURE__*/function () {
|
|
|
404
280
|
}
|
|
405
281
|
}]);
|
|
406
282
|
return SecurityService;
|
|
407
|
-
}();
|
|
283
|
+
}();
|
|
284
|
+
_defineProperty(SecurityService, "securitySdkMap", new Map());
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IsecurityConfig, ProductSceneEnum, DeviceIdParameter } from '../../../types';
|
|
2
|
-
import type { ApdidEnvironment } from '../../../util/jshield-apdid';
|
|
3
2
|
export declare const getSecurityConfigStorageKey: (scene: ProductSceneEnum) => string;
|
|
4
3
|
export declare enum SecurityRegionEnum {
|
|
5
4
|
SG = "SG",
|
|
@@ -23,30 +22,10 @@ export declare const sceneMap: {
|
|
|
23
22
|
};
|
|
24
23
|
export declare const getSecurityHost: (region: string) => string;
|
|
25
24
|
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;
|
|
30
25
|
export declare class Security {
|
|
31
26
|
scene: string;
|
|
32
27
|
h5gateway: string;
|
|
33
|
-
|
|
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;
|
|
28
|
+
constructor(options: IsecurityConfig);
|
|
50
29
|
initSecurity(successCallback: any, failCallback: any): void;
|
|
51
30
|
private initToken;
|
|
52
31
|
pollingGetApdidToken(config?: DeviceIdParameter): Promise<string>;
|