@alipay/ams-checkout 2.0.20 → 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.
Files changed (51) hide show
  1. package/ams-checkout.js +3 -3
  2. package/dist/ams-checkout.min.js +1 -1
  3. package/esm/config/index.d.ts +7 -0
  4. package/esm/config/index.js +2 -2
  5. package/esm/constant/element.d.ts +2 -1
  6. package/esm/constant/element.js +1 -0
  7. package/esm/constant/index.d.ts +4 -21
  8. package/esm/core/component/element/elementController/index.d.ts +3 -3
  9. package/esm/core/component/element/elementController/index.js +66 -42
  10. package/esm/core/component/element/elementProcessor/paymentProcessor.js +13 -10
  11. package/esm/core/component/element/index.d.ts +4 -1
  12. package/esm/core/component/element/index.js +19 -4
  13. package/esm/core/component/element/mock.js +1 -1
  14. package/esm/core/component/element/modernElementController/adapter.d.ts +19 -0
  15. package/esm/core/component/element/modernElementController/adapter.js +79 -0
  16. package/esm/core/component/element/modernElementController/index.d.ts +155 -0
  17. package/esm/core/component/element/modernElementController/index.js +1780 -0
  18. package/esm/core/component/element/type.d.ts +16 -18
  19. package/esm/core/instance/index.d.ts +12 -4
  20. package/esm/core/instance/index.js +152 -26
  21. package/esm/foundation/service/event-center.js +1 -1
  22. package/esm/foundation/service/security/index.d.ts +9 -4
  23. package/esm/foundation/service/security/index.js +158 -35
  24. package/esm/foundation/service/security/security.d.ts +22 -1
  25. package/esm/foundation/service/security/security.js +150 -37
  26. package/esm/foundation/utils/preload_helper.d.ts +6 -3
  27. package/esm/foundation/utils/preload_helper.js +122 -32
  28. package/esm/main.js +4 -4
  29. package/esm/modern/global.d.ts +3 -0
  30. package/esm/modern/index.d.ts +5 -1
  31. package/esm/modern/index.js +1 -51
  32. package/esm/modern/tools.js +1 -0
  33. package/esm/plugin/component/channel.d.ts +2 -2
  34. package/esm/plugin/component/channel.js +18 -18
  35. package/esm/plugin/component/index.js +36 -29
  36. package/esm/tsdoc-metadata.json +1 -1
  37. package/esm/types/index.d.ts +1 -0
  38. package/esm/util/beforeConfirm.d.ts +4 -2
  39. package/esm/util/beforeConfirm.js +15 -14
  40. package/esm/util/jshield-apdid/apdid-loader.js +377 -0
  41. package/esm/util/jshield-apdid/index.js +21 -0
  42. package/esm/util/logger.js +1 -2
  43. package/esm/util/security-registry.d.ts +72 -0
  44. package/esm/util/security-registry.js +175 -0
  45. package/esm/util/security.d.ts +22 -1
  46. package/esm/util/security.js +150 -39
  47. package/package.json +15 -9
  48. package/types.d.ts +840 -1103
  49. package/types.untrimmed.d.ts +992 -1122
  50. package/esm/modern/stageName.d.ts +0 -3
  51. package/esm/modern/stageName.js +0 -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
- securitySDK = _this._getSecuritySDKByProductScene({
55
- product: (deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.productScene) || _this.productScene
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 = 15;
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 = 10;
71
+ _context.next = 13;
64
72
  break;
65
73
  }
66
- _context.next = 7;
74
+ _context.next = 10;
67
75
  return securitySDK.pollingGetApdidToken(deviceIdParameter);
68
- case 7:
76
+ case 10:
69
77
  _context.t0 = _context.sent;
70
- _context.next = 13;
78
+ _context.next = 16;
71
79
  break;
72
- case 10:
73
- _context.next = 12;
80
+ case 13:
81
+ _context.next = 15;
74
82
  return securitySDK.getApdidToken();
75
- case 12:
83
+ case 15:
76
84
  _context.t0 = _context.sent;
77
- case 13:
85
+ case 16:
78
86
  deviceId = _context.t0;
79
87
  _this.logDeviceId(deviceId, getDeviceIdStartTime);
80
- case 15:
88
+ case 18:
81
89
  resolve(deviceId);
82
- case 16:
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
- if (!this._getSecuritySDKByProductScene({
156
- product: this.productScene
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 5:
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 7:
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
- * @description Obtain security SDK through scenario identification
303
+ * Get the scene string from product enum
231
304
  */
232
305
  }, {
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;
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 New security SDK through scenario identification
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
- SecurityService.securitySdkMap.set(scene, securitySdk);
256
- securitySdk.initSecurity(successCallback, failCallback);
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
- constructor(options: IsecurityConfig);
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 APDID from "../../../util/jshield-apdid/apdid-core.umd.min";
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
- this.initToken(successCallback, failCallback);
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) {
@@ -64,7 +166,6 @@ export var Security = /*#__PURE__*/function () {
64
166
  } else {
65
167
  failCallback && failCallback(msg);
66
168
  }
67
- console.log('initToken result tokenResult', JSON.stringify(tokenResult), msg);
68
169
  });
69
170
  } catch (error) {
70
171
  failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
@@ -73,48 +174,48 @@ export var Security = /*#__PURE__*/function () {
73
174
  }, {
74
175
  key: "pollingGetApdidToken",
75
176
  value: function () {
76
- var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(config) {
77
- var _this = this;
177
+ var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
178
+ var _this2 = this;
78
179
  var tokenCollectTime, dataPollingInterval, asyncFunc;
79
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
80
- while (1) switch (_context3.prev = _context3.next) {
180
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
181
+ while (1) switch (_context4.prev = _context4.next) {
81
182
  case 0:
82
183
  tokenCollectTime = parseInt((config === null || config === void 0 ? void 0 : config.tokenCollectTime) || '0', 10);
83
184
  dataPollingInterval = parseInt((config === null || config === void 0 ? void 0 : config.dataPollingInterval) || '500', 10);
84
185
  asyncFunc = /*#__PURE__*/function () {
85
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
186
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
86
187
  var deviceId, interval, polling;
87
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
88
- while (1) switch (_context2.prev = _context2.next) {
188
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
189
+ while (1) switch (_context3.prev = _context3.next) {
89
190
  case 0:
90
- _context2.next = 2;
91
- return _this.getApdidToken();
191
+ _context3.next = 2;
192
+ return _this2.getApdidToken();
92
193
  case 2:
93
- deviceId = _context2.sent;
194
+ deviceId = _context3.sent;
94
195
  if (!deviceId) {
95
- _context2.next = 5;
196
+ _context3.next = 5;
96
197
  break;
97
198
  }
98
- return _context2.abrupt("return", resolve(deviceId));
199
+ return _context3.abrupt("return", resolve(deviceId));
99
200
  case 5:
100
201
  polling = /*#__PURE__*/function () {
101
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
102
- return _regeneratorRuntime().wrap(function _callee$(_context) {
103
- while (1) switch (_context.prev = _context.next) {
202
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
203
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
204
+ while (1) switch (_context2.prev = _context2.next) {
104
205
  case 0:
105
- _context.next = 2;
106
- return _this.getApdidToken();
206
+ _context2.next = 2;
207
+ return _this2.getApdidToken();
107
208
  case 2:
108
- deviceId = _context.sent;
209
+ deviceId = _context2.sent;
109
210
  if (deviceId) {
110
211
  clearInterval(interval);
111
212
  resolve(deviceId);
112
213
  }
113
214
  case 4:
114
215
  case "end":
115
- return _context.stop();
216
+ return _context2.stop();
116
217
  }
117
- }, _callee);
218
+ }, _callee2);
118
219
  }));
119
220
  return function polling() {
120
221
  return _ref2.apply(this, arguments);
@@ -127,22 +228,22 @@ export var Security = /*#__PURE__*/function () {
127
228
  }, tokenCollectTime);
128
229
  case 8:
129
230
  case "end":
130
- return _context2.stop();
231
+ return _context3.stop();
131
232
  }
132
- }, _callee2);
233
+ }, _callee3);
133
234
  }));
134
235
  return function asyncFunc(_x2) {
135
236
  return _ref.apply(this, arguments);
136
237
  };
137
238
  }();
138
- return _context3.abrupt("return", new Promise(function (resolve) {
239
+ return _context4.abrupt("return", new Promise(function (resolve) {
139
240
  asyncFunc(resolve);
140
241
  }));
141
242
  case 4:
142
243
  case "end":
143
- return _context3.stop();
244
+ return _context4.stop();
144
245
  }
145
- }, _callee3);
246
+ }, _callee4);
146
247
  }));
147
248
  function pollingGetApdidToken(_x) {
148
249
  return _pollingGetApdidToken.apply(this, arguments);
@@ -152,25 +253,37 @@ export var Security = /*#__PURE__*/function () {
152
253
  }, {
153
254
  key: "getApdidToken",
154
255
  value: function () {
155
- var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
156
- var _this2 = this;
157
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
158
- while (1) switch (_context4.prev = _context4.next) {
256
+ var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
257
+ var _this3 = this;
258
+ var loaded;
259
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
260
+ while (1) switch (_context5.prev = _context5.next) {
159
261
  case 0:
160
- return _context4.abrupt("return", new Promise(function (resolve) {
262
+ _context5.next = 2;
263
+ return this.ensureApdidLoaded();
264
+ case 2:
265
+ loaded = _context5.sent;
266
+ if (loaded) {
267
+ _context5.next = 5;
268
+ break;
269
+ }
270
+ return _context5.abrupt("return", '');
271
+ case 5:
272
+ return _context5.abrupt("return", new Promise(function (resolve) {
161
273
  try {
162
- APDID === null || APDID === void 0 || APDID.getApdidToken(_this2.scene, function (tokenResult) {
274
+ var APDID = _this3.getAPDIDModule();
275
+ APDID === null || APDID === void 0 || APDID.getApdidToken(_this3.scene, function (tokenResult) {
163
276
  resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
164
277
  });
165
278
  } catch (error) {
166
279
  resolve('');
167
280
  }
168
281
  }));
169
- case 1:
282
+ case 6:
170
283
  case "end":
171
- return _context4.stop();
284
+ return _context5.stop();
172
285
  }
173
- }, _callee4);
286
+ }, _callee5, this);
174
287
  }));
175
288
  function getApdidToken() {
176
289
  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
- static preloadSecuritySDK(product: ProductSceneEnum, securityRegion?: string): void;
9
- static getSecuritySdk(scene: any): Security;
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;