补齐移动壳深链失败观测
移动壳 Deep Link 解析返回状态并记录拒绝路径 ShellApp 记录初始链接读取失败且保留安全入口 移动壳配置检查和文档同步深链失败边界
This commit is contained in:
@@ -6,6 +6,13 @@ import {
|
||||
|
||||
const supportedHosts = new Set(['open', 'app']);
|
||||
|
||||
type MobileShellDeepLinkResolutionStatus = 'default' | 'mapped' | 'rejected';
|
||||
|
||||
export type MobileShellDeepLinkResolution = {
|
||||
status: MobileShellDeepLinkResolutionStatus;
|
||||
url: string;
|
||||
};
|
||||
|
||||
function extractPathFromNativeUrl(url: URL) {
|
||||
if (supportedHosts.has(url.hostname)) {
|
||||
return `${url.pathname}${url.search}${url.hash}`;
|
||||
@@ -53,17 +60,34 @@ export function buildMobileShellUrlFromDeepLink(
|
||||
baseWebUrl: string,
|
||||
options: MobileShellUrlOptions,
|
||||
) {
|
||||
return resolveMobileShellUrlFromDeepLink(rawUrl, baseWebUrl, options).url;
|
||||
}
|
||||
|
||||
export function resolveMobileShellUrlFromDeepLink(
|
||||
rawUrl: string | null | undefined,
|
||||
baseWebUrl: string,
|
||||
options: MobileShellUrlOptions,
|
||||
): MobileShellDeepLinkResolution {
|
||||
const normalizedBaseWebUrl = resolveMobileShellBaseWebUrl(baseWebUrl);
|
||||
const defaultUrl = buildMobileShellUrl(normalizedBaseWebUrl, options);
|
||||
if (!rawUrl) {
|
||||
return defaultUrl;
|
||||
return {
|
||||
status: 'default',
|
||||
url: defaultUrl,
|
||||
};
|
||||
}
|
||||
|
||||
const webOrigin = new URL(normalizedBaseWebUrl).origin;
|
||||
const targetPath = resolveTargetPath(rawUrl, webOrigin);
|
||||
if (!targetPath) {
|
||||
return defaultUrl;
|
||||
return {
|
||||
status: 'rejected',
|
||||
url: defaultUrl,
|
||||
};
|
||||
}
|
||||
|
||||
return buildMobileShellUrl(new URL(targetPath, webOrigin).toString(), options);
|
||||
return {
|
||||
status: 'mapped',
|
||||
url: buildMobileShellUrl(new URL(targetPath, webOrigin).toString(), options),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user