feat(platform,datalink,bill): add workflow job drilldown, safe record batch-edit, audit, and spec linkage diagnostics (v0.8.11)
This commit is contained in:
1 parent
2ec08033e0
commit
a0ec7f95a7
37 files changed
+3958
-674
No files matched your search
+79
-7
@@ -15,6 +15,7 @@ import {
|
||||
setActiveAccount,
|
||||
AccountEntry,
|
||||
} from "./account-store.js";
|
||||
import { clearCorpTokens } from "./token-store.js";
|
||||
import {
|
||||
CorporationItem,
|
||||
CorporationItemSchema,
|
||||
@@ -1124,6 +1125,59 @@ export function resolveLinkExpiresAt(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function parseExpiresInSeconds(
|
||||
value?: string | number,
|
||||
fallbackSeconds = 7200
|
||||
): number {
|
||||
if (value === undefined || value === null || String(value).trim() === "") {
|
||||
return fallbackSeconds;
|
||||
}
|
||||
if (typeof value === "number") {
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
throw new AuthenticationError(`有效期秒数必须是大于 0 的数字: ${value}`);
|
||||
}
|
||||
return Math.round(value);
|
||||
}
|
||||
const raw = String(value).trim().toLowerCase();
|
||||
const match = raw.match(
|
||||
/^(\d+(?:\.\d+)?)\s*(s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)?$/
|
||||
);
|
||||
if (!match) {
|
||||
throw new AuthenticationError(
|
||||
`无效的有效期参数: ${value}(支持秒数如 86400,或带单位如 30m、24h、3d)`
|
||||
);
|
||||
}
|
||||
const amount = Number(match[1]);
|
||||
if (!Number.isFinite(amount) || amount <= 0) {
|
||||
throw new AuthenticationError(`有效期必须是大于 0 的数字: ${value}`);
|
||||
}
|
||||
const unit = match[2] || "s";
|
||||
if (["s", "sec", "secs", "second", "seconds"].includes(unit)) {
|
||||
return Math.round(amount);
|
||||
}
|
||||
if (["m", "min", "mins", "minute", "minutes"].includes(unit)) {
|
||||
return Math.round(amount * 60);
|
||||
}
|
||||
if (["h", "hr", "hrs", "hour", "hours"].includes(unit)) {
|
||||
return Math.round(amount * 3600);
|
||||
}
|
||||
return Math.round(amount * 86400);
|
||||
}
|
||||
|
||||
export function invalidateCorpSubdomainTokenCaches(corp: CorpConfig): void {
|
||||
try {
|
||||
clearCorpTokens(corp.id);
|
||||
if (corp.corpId && corp.corpId !== corp.id) {
|
||||
clearCorpTokens(corp.corpId);
|
||||
}
|
||||
if (corp.credentials?.corpId && corp.credentials.corpId !== corp.id) {
|
||||
clearCorpTokens(corp.credentials.corpId);
|
||||
}
|
||||
} catch {
|
||||
// Ignore cache cleanup errors in restricted environments
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析从 F12 抓包复制出来的 Request Headers、cURL 命令或 URL 字符串
|
||||
*/
|
||||
@@ -1675,7 +1729,8 @@ export async function elevateCorpWithOpenApiKey(
|
||||
export async function getCorpProvisionalAuthLink(
|
||||
corp: CorpConfig,
|
||||
options: {
|
||||
expiresIn?: number;
|
||||
expiresIn?: number | string;
|
||||
ttl?: number | string;
|
||||
pageType?: string;
|
||||
force?: boolean;
|
||||
syncLocalSession?: boolean;
|
||||
@@ -1693,7 +1748,8 @@ export async function getCorpProvisionalAuthLink(
|
||||
persistent: boolean;
|
||||
method: "provisional-openapi" | "session-token";
|
||||
}> {
|
||||
const expiresIn = options.expiresIn && options.expiresIn > 0 ? options.expiresIn : 7200;
|
||||
const explicitDuration = options.expiresIn ?? options.ttl;
|
||||
const expiresIn = parseExpiresInSeconds(explicitDuration, 7200);
|
||||
const pageType = options.pageType || "home";
|
||||
const corpId = corp.corpId || corp.credentials.corpId;
|
||||
const staffId = corp.staffId || corp.credentials.staffId;
|
||||
@@ -1737,6 +1793,7 @@ export async function getCorpProvisionalAuthLink(
|
||||
corp.session.expTime = provisional.expiresAt;
|
||||
}
|
||||
saveCorpConfig(corp, options.enterprisesDir);
|
||||
invalidateCorpSubdomainTokenCaches(corp);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -1760,13 +1817,25 @@ export async function getCorpProvisionalAuthLink(
|
||||
);
|
||||
}
|
||||
|
||||
const expMs = corp.auth?.expiresAt || corp.session?.expTime || Date.now() + expiresIn * 1000;
|
||||
const expMs =
|
||||
explicitDuration !== undefined
|
||||
? Date.now() + expiresIn * 1000
|
||||
: corp.auth?.expiresAt || corp.session?.expTime || Date.now() + expiresIn * 1000;
|
||||
if (expMs <= Date.now() && !canRefreshCorpAccessToken(corp)) {
|
||||
throw new AuthenticationError(
|
||||
`企业 [${corp.name}] 临时凭证已过期且未配置持久化密钥,请使用 hose-use corps add-link 重新导入。`
|
||||
);
|
||||
}
|
||||
|
||||
if (explicitDuration !== undefined && options.syncLocalSession !== false) {
|
||||
if (!corp.auth) corp.auth = { refreshTtl: 300 };
|
||||
corp.auth.expiresAt = expMs;
|
||||
if (corp.session) {
|
||||
corp.session.expTime = expMs;
|
||||
}
|
||||
saveCorpConfig(corp, options.enterprisesDir);
|
||||
}
|
||||
|
||||
const url = `${baseUrl}/web/thirdparty.html?accessToken=${encodeURIComponent(
|
||||
corp.credentials.accessToken
|
||||
)}&ekbCorpId=${encodeURIComponent(corpId)}&pageType=${encodeURIComponent(
|
||||
@@ -1780,7 +1849,7 @@ export async function getCorpProvisionalAuthLink(
|
||||
staffName: corp.staffName || corp.session?.staffName || undefined,
|
||||
url,
|
||||
token: corp.credentials.accessToken,
|
||||
expiresIn: Math.max(1, Math.floor((expMs - Date.now()) / 1000)),
|
||||
expiresIn: Math.max(1, Math.round((expMs - Date.now()) / 1000)),
|
||||
expiresAt: formatBeijingIso(expMs),
|
||||
persistent: canRefreshCorpAccessToken(corp),
|
||||
method: "session-token",
|
||||
@@ -1917,7 +1986,8 @@ export async function switchCorporationAndExchangeToken(
|
||||
export async function refreshSingleCorpAccessToken(
|
||||
corp: CorpConfig,
|
||||
businessCenterUrl: string = DEFAULT_BUSINESS_CENTER_URL,
|
||||
idpUrl: string = DEFAULT_IDP_URL
|
||||
idpUrl: string = DEFAULT_IDP_URL,
|
||||
enterprisesDir?: string
|
||||
): Promise<boolean> {
|
||||
if (!canRefreshCorpAccessToken(corp)) return false;
|
||||
|
||||
@@ -1951,7 +2021,8 @@ export async function refreshSingleCorpAccessToken(
|
||||
corp.auth.refreshToken = res.refreshToken;
|
||||
corp.auth.expiresAt = Date.now() + res.expiresIn * 1000;
|
||||
|
||||
saveCorpConfig(corp);
|
||||
saveCorpConfig(corp, enterprisesDir);
|
||||
invalidateCorpSubdomainTokenCaches(corp);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (!hasOpenApiPersistentCredentials(corp)) {
|
||||
@@ -1989,7 +2060,8 @@ export async function refreshSingleCorpAccessToken(
|
||||
corp.session.expTime = provisional.expiresAt;
|
||||
}
|
||||
|
||||
saveCorpConfig(corp);
|
||||
saveCorpConfig(corp, enterprisesDir);
|
||||
invalidateCorpSubdomainTokenCaches(corp);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
|
||||
Reference in new issue
Block a user