@alipay/ams-checkout 0.0.1783663570-dev.7 → 0.0.1783663570-dev.9
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/dist/ams-checkout.min.js.map +1 -1
- package/esm/config/index.js +1 -1
- package/esm/core/component/element/modernElementController/index.d.ts +2 -0
- package/esm/core/component/element/modernElementController/index.js +69 -39
- package/esm/modern/tools.js +1 -1
- package/esm/util/jshield-apdid/apdid-loader.js +65 -28
- package/esm/util/logger.js +1 -1
- package/package.json +1 -1
- package/types.d.ts +5 -0
- package/types.untrimmed.d.ts +5 -0
|
@@ -19,7 +19,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
19
19
|
* - Concurrent call dedup (shared loadingPromise)
|
|
20
20
|
* - State management: idle -> loading -> ready/failed
|
|
21
21
|
* - Monitoring event hooks (onLoad callback)
|
|
22
|
-
* - Uses
|
|
22
|
+
* - Uses a module script for ESM modules to avoid dynamic import syntax in the UMD bundle
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/** Environment type for CDN URL selection */
|
|
@@ -61,9 +61,9 @@ var APDID_GLOBAL_NAME = 'APDID';
|
|
|
61
61
|
* ApdidLoader - Singleton class responsible for async loading the apdid-core ESM module.
|
|
62
62
|
*
|
|
63
63
|
* Key behaviors:
|
|
64
|
-
* - Uses
|
|
64
|
+
* - Uses a module script to load ESM modules
|
|
65
65
|
* - Concurrent calls share the same loading promise
|
|
66
|
-
* - On success, the module
|
|
66
|
+
* - On success, the APDID global exposed by the module is stored internally
|
|
67
67
|
* - On failure/timeout, the loader degrades gracefully and getApdidModule() returns undefined
|
|
68
68
|
*/
|
|
69
69
|
export var ApdidLoader = /*#__PURE__*/function () {
|
|
@@ -252,7 +252,7 @@ export var ApdidLoader = /*#__PURE__*/function () {
|
|
|
252
252
|
return _loadWithRetry;
|
|
253
253
|
}()
|
|
254
254
|
/**
|
|
255
|
-
* Internal method: attempt to load the ESM module once via
|
|
255
|
+
* Internal method: attempt to load the ESM module once via a module script (no retry)
|
|
256
256
|
*/
|
|
257
257
|
)
|
|
258
258
|
}, {
|
|
@@ -260,35 +260,72 @@ export var ApdidLoader = /*#__PURE__*/function () {
|
|
|
260
260
|
value: function _loadModuleOnce(url, config) {
|
|
261
261
|
var _this2 = this;
|
|
262
262
|
var startTime = Date.now();
|
|
263
|
-
var timeoutId;
|
|
264
263
|
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
} else {
|
|
278
|
-
throw new Error("[ApdidLoader] Module loaded but no export and window.".concat(APDID_GLOBAL_NAME, " not found"));
|
|
279
|
-
}
|
|
264
|
+
// Older WebViews ignore module scripts without firing load/error events.
|
|
265
|
+
// Fail fast so the existing retry/degradation flow does not wait for two 10s timeouts.
|
|
266
|
+
if (!('noModule' in document.createElement('script'))) {
|
|
267
|
+
return Promise.reject(new Error('[ApdidLoader] Module scripts are not supported'));
|
|
268
|
+
}
|
|
269
|
+
return new Promise(function (resolve, reject) {
|
|
270
|
+
var globalWindow = window;
|
|
271
|
+
var loadedApdid = globalWindow.APDID;
|
|
272
|
+
if (loadedApdid) {
|
|
273
|
+
_this2._onLoadSuccess(loadedApdid, startTime, config);
|
|
274
|
+
resolve();
|
|
275
|
+
return;
|
|
280
276
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
277
|
+
var existingScript = Array.from(document.querySelectorAll('script[type="module"]')).find(function (candidate) {
|
|
278
|
+
return candidate.src === url;
|
|
279
|
+
});
|
|
280
|
+
var script = existingScript || document.createElement('script');
|
|
281
|
+
var settled = false;
|
|
282
|
+
var cleanup = function cleanup() {
|
|
283
|
+
clearTimeout(timeoutId);
|
|
284
|
+
script.removeEventListener('load', handleLoad);
|
|
285
|
+
script.removeEventListener('error', handleError);
|
|
286
|
+
};
|
|
287
|
+
var rejectLoad = function rejectLoad(error) {
|
|
288
|
+
if (settled) return;
|
|
289
|
+
settled = true;
|
|
290
|
+
cleanup();
|
|
291
|
+
|
|
292
|
+
// Remove failed scripts so the transparent retry can append a fresh one.
|
|
293
|
+
if (script.parentNode) {
|
|
294
|
+
script.parentNode.removeChild(script);
|
|
295
|
+
}
|
|
296
|
+
reject(error);
|
|
297
|
+
};
|
|
298
|
+
var handleLoad = function handleLoad() {
|
|
299
|
+
if (settled) return;
|
|
300
|
+
var apdidCore = globalWindow.APDID;
|
|
301
|
+
if (!apdidCore) {
|
|
302
|
+
rejectLoad(new Error("[ApdidLoader] Module loaded but window.".concat(APDID_GLOBAL_NAME, " not found")));
|
|
303
|
+
return;
|
|
288
304
|
}
|
|
305
|
+
settled = true;
|
|
306
|
+
cleanup();
|
|
307
|
+
_this2._onLoadSuccess(apdidCore, startTime, config);
|
|
308
|
+
resolve();
|
|
309
|
+
};
|
|
310
|
+
var handleError = function handleError() {
|
|
311
|
+
rejectLoad(new Error("[ApdidLoader] Failed to load module script: ".concat(url)));
|
|
312
|
+
};
|
|
313
|
+
var timeoutId = setTimeout(function () {
|
|
314
|
+
var _config$callbacks4, _config$callbacks4$on;
|
|
315
|
+
if (settled) return;
|
|
316
|
+
(_config$callbacks4 = config.callbacks) === null || _config$callbacks4 === void 0 || (_config$callbacks4$on = _config$callbacks4.onLoadTimeout) === null || _config$callbacks4$on === void 0 || _config$callbacks4$on.call(_config$callbacks4);
|
|
317
|
+
rejectLoad(new Error("[ApdidLoader] Module load timeout after ".concat(LOAD_TIMEOUT_MS, "ms: ").concat(url)));
|
|
289
318
|
}, LOAD_TIMEOUT_MS);
|
|
319
|
+
script.addEventListener('load', handleLoad);
|
|
320
|
+
script.addEventListener('error', handleError);
|
|
321
|
+
if (!existingScript) {
|
|
322
|
+
script.type = 'module';
|
|
323
|
+
script.src = url;
|
|
324
|
+
script.async = true;
|
|
325
|
+
script.crossOrigin = 'anonymous';
|
|
326
|
+
(document.head || document.getElementsByTagName('head')[0]).appendChild(script);
|
|
327
|
+
}
|
|
290
328
|
});
|
|
291
|
-
return Promise.race([importPromise, timeoutPromise]);
|
|
292
329
|
}
|
|
293
330
|
|
|
294
331
|
/**
|
package/esm/util/logger.js
CHANGED
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -3238,6 +3238,11 @@ export declare class ExpressElement extends BaseMainElement<ExpressElementConfig
|
|
|
3238
3238
|
/** setup 阶段的 renderData,仅供非 Safari PC Apple Pay host-token 路径读取 paymentRequest。 */
|
|
3239
3239
|
private _renderData;
|
|
3240
3240
|
private _hostSign;
|
|
3241
|
+
/**
|
|
3242
|
+
* 构造时传入的初始金额。cleanAppConfig 已剔除 amount,setup 阶段透传给 iframe(PayPal 按钮首屏需要)
|
|
3243
|
+
* 与 PayPal channelClientId 查询仍需读它;运行时改额只能走 updateConfig。
|
|
3244
|
+
*/
|
|
3245
|
+
private _initialAmount;
|
|
3241
3246
|
/**
|
|
3242
3247
|
* 本地事件处理器(绕过 bridge 的 host→webapp 方向限制)。
|
|
3243
3248
|
* bridge.on 只能监听 iframe 发来的消息;SDK host 主动推送事件给商户时走 _emit → _localHandlers。
|
package/types.untrimmed.d.ts
CHANGED
|
@@ -3656,6 +3656,11 @@ export declare class ExpressElement extends BaseMainElement<ExpressElementConfig
|
|
|
3656
3656
|
/** setup 阶段的 renderData,仅供非 Safari PC Apple Pay host-token 路径读取 paymentRequest。 */
|
|
3657
3657
|
private _renderData;
|
|
3658
3658
|
private _hostSign;
|
|
3659
|
+
/**
|
|
3660
|
+
* 构造时传入的初始金额。cleanAppConfig 已剔除 amount,setup 阶段透传给 iframe(PayPal 按钮首屏需要)
|
|
3661
|
+
* 与 PayPal channelClientId 查询仍需读它;运行时改额只能走 updateConfig。
|
|
3662
|
+
*/
|
|
3663
|
+
private _initialAmount;
|
|
3659
3664
|
/**
|
|
3660
3665
|
* 本地事件处理器(绕过 bridge 的 host→webapp 方向限制)。
|
|
3661
3666
|
* bridge.on 只能监听 iframe 发来的消息;SDK host 主动推送事件给商户时走 _emit → _localHandlers。
|