feat(workflow): 保存期接口权限预检与 choose 表达式序列化开关
## 一、保存期「接口 → 应用」权限预检
工作流 HTTP 节点调用某些开放接口前,企业必须先开通对应应用,否则运行时
返回 403「未开通功能,无权访问」,而该报文字段里完全看不出缺哪个应用。
真实案例:某客户「单据审批」应用未开通,流程跑到第 9 步才被网关拦下,
排查成本极高。
本次在保存/静态分析阶段按接口路径反推所需应用:
- 新增 `analysis/openapi-app-requirements.ts`:接口路径 → 所需应用的映射表
(首条 `/api/openapi/v1/backlog/data/` + POST/PUT/PATCH → 「单据审批」
`TICKET_AUDIT_switch`、productId `o0hMBw000000g0`),配套
`extractStaticUrlPath`(去域名、截断到第一个 `@{`、去 query/hash)与
`matchAppRequirement`。
- `analysis/analyzer.ts` 6.3 节重构:以路径反查为主,节点显式声明的
`powerCode`(`params` / URL query)作为交叉印证;两者指向同一权限时走
路径规则,以便报文带上接口名、应用名、productId 与判定依据路径。显式
声明了其它 `powerCode` 时以声明为准,避免两套规则打架。
- 新增保存期钩子 `preflightNodeAppRequirements` / `renderAppRequirementAlerts`
(`cli/commands/workflow/shared.ts`),接入 `node add` / `node edit`:
只检查本次写入的 HTTP 节点,未开通则输出 ⛔ 段并在 JSON 模式落到
`appRequirementAlerts`;读不到企业应用清单时降级为 ⚠️,不阻断写入。
- `domains/store/tools.ts` 抽出 `isClientGoodOpened` 与
`fetchOpenedPowerCodes`,`workflow analyze` 改为复用,移除内联汇总逻辑
(`isClientGoodOpened` 仍从 `analyze.ts` 再导出以保持既有契约)。
判定边界(刻意收紧,宁可漏报不误报):只对 HTTP 节点生效;URL 若整体由
上游节点变量拼接则完全不判断;无法静态读出接口路径时不做任何猜测性告警。
## 二、choose 表达式序列化开关
合思前端序列化模板字符串时多写了一个右花括号,产出 `...}')}` 形态;
后端 Jackson 默认未开启 `FAIL_ON_TRAILING_TOKENS`,尾随 `}` 被静默忽略,
因此该形态在引擎侧可正常执行。
- 新增 `models/choose-serialization.ts`:`frontend` / `pure` 双模式序列化,
以及 `parseChoosePayloadLoose`(逐个剥离尾部多余 `}` 再解析)。
- 全局配置新增 `chooseSerialization`,默认 `frontend`(与设计器字节一致),
可用 `--choose-serialization` 单次覆盖;读取侧永远双形态兼容。
- 修复 `branch/explain.ts` 的 `parseChooseTag` 在 `}}` 形态下静默返回 null
的缺陷,该缺陷会导致真实数据上的分支解释与字段引用分析失效。
## 测试
新增 24 个用例,覆盖:
- `choose-serialization.test.ts`:双模式序列化与宽松解析
- `openapi-app-requirements.test.ts`:静态路径提取、路径命中、方法不符跳过、
纯变量 URL 跳过、非 HTTP 节点不判断、未开通/已开通/无清单三种诊断
- `shared.app-preflight.test.ts`:预检只处理 HTTP 节点、动态 URL 跳过、
读不到清单降级不阻断、告警分级渲染
`bun test` 1068 pass / 0 fail;`bun run check` 零错误;`check:readme` 通过。
## 实机核对(全部只读,未触碰任何生产流程配置)
- 真实流程的两个 HTTP 节点均命中「单据审批」;同时确认设计器确实会把
`powerCode` 写入节点 `params`,因此显式声明与路径反推两条规则都需要保留。
- 已开通该应用的企业 → 无诊断;未开通的企业 → 精确打出硬门禁并指向具体
节点 key 与判定依据路径。
This commit is contained in:
1 parent
33f3275acb
commit
7a19fa8337
14 files changed
+1003
-36
No files matched your search
@@ -73,11 +73,14 @@ async function handleShow(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
"测试企业目录": globalConfig.testEnterprisesDir || "未配置 (仅读全局用户企业)",
|
||||
"默认自更新仓库": globalConfig.updateRepo || "官方默认 (yunyingk/hose-use)",
|
||||
"自更新源偏好": globalConfig.updateSource || "auto (自动择优)",
|
||||
"choose 表达式形态": globalConfig.chooseSerialization === "pure"
|
||||
? "pure (配平形态, JSON 合法)"
|
||||
: "frontend (百分百模拟设计器, 多一个右花括号 — 默认)",
|
||||
"配置文件路径": configPath,
|
||||
});
|
||||
|
||||
return {
|
||||
stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose-use config mode <stateful|stateless>\n 指定企业: hose-use corps switch <corpId>\n 配置测试目录: hose-use config test-dir <dir> (或 --clear)\n 更新源设置: hose-use config set updateSource <auto|github|gitea>\n`,
|
||||
stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose-use config mode <stateful|stateless>\n 指定企业: hose-use corps switch <corpId>\n 配置测试目录: hose-use config test-dir <dir> (或 --clear)\n 更新源设置: hose-use config set updateSource <auto|github|gitea>\n choose 形态: hose-use config set chooseSerialization <frontend|pure>\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -214,10 +217,21 @@ async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise<Cl
|
||||
};
|
||||
}
|
||||
partial.updateSource = srcLower;
|
||||
} else if (keyLower === "chooseserialization" || keyLower === "choose") {
|
||||
resolvedKey = "chooseSerialization";
|
||||
const modeLower = val.toLowerCase();
|
||||
if (modeLower !== "frontend" && modeLower !== "pure") {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `不支持的 chooseSerialization 值: ${val}。可选: frontend (默认, 与设计器产出一致, 多一个右花括号), pure (配平形态)\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
partial.chooseSerialization = modeLower;
|
||||
} else {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `不支持配置键: ${rawKey}。支持: stateful, defaultCorpId, defaultAccountId, testEnterprisesDir, updateRepo, updateSource\n`,
|
||||
stderr: `不支持配置键: ${rawKey}。支持: stateful, defaultCorpId, defaultAccountId, testEnterprisesDir, updateRepo, updateSource, chooseSerialization\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ import { stringOption, booleanOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
import { isClientGoodOpened } from "../../../domains/store/tools.js";
|
||||
|
||||
export function isClientGoodOpened(item: { status?: string | null; onLineStatus?: string | null }): boolean {
|
||||
return item.status?.toUpperCase() === "OPENED";
|
||||
}
|
||||
export { isClientGoodOpened };
|
||||
|
||||
export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
@@ -46,22 +45,8 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
|
||||
let openedPowerCodes: Set<string> | undefined;
|
||||
try {
|
||||
const { fetchClientGoods } = await import("../../../domains/store/tools.js");
|
||||
const goods = await fetchClientGoods(runtime.selectedCorp!, { isAll: true });
|
||||
const codes = new Set<string>();
|
||||
for (const item of goods) {
|
||||
const isOpened = isClientGoodOpened(item);
|
||||
if (isOpened && Array.isArray(item.powers)) {
|
||||
for (const power of item.powers) {
|
||||
if (typeof power === "string") {
|
||||
codes.add(power.toLowerCase());
|
||||
} else if (power && typeof power === "object" && power.powerCode) {
|
||||
codes.add(power.powerCode.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
openedPowerCodes = codes;
|
||||
const { fetchOpenedPowerCodes } = await import("../../../domains/store/tools.js");
|
||||
openedPowerCodes = await fetchOpenedPowerCodes(runtime.selectedCorp!);
|
||||
} catch (error) {
|
||||
evidenceErrors.push({ source: "openedPowerCodes", message: error instanceof Error ? error.message : String(error) });
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import { stringOption, numberOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createWorkflowDetailClient, formatWorkflowVersion } from "./shared.js";
|
||||
import { createWorkflowDetailClient, formatWorkflowVersion, resolveChooseSerialization, normalizeNodeExpressionFields, preflightNodeAppRequirements, renderAppRequirementAlerts } from "./shared.js";
|
||||
import { handleGrantNodes, handleListAvailableNodes } from "./node-catalog.js";
|
||||
|
||||
async function saveNodeChanges(client: Parameters<typeof getWorkflowDetail>[0], original: WorkflowDetail, updated: WorkflowDetail, platformId?: string) {
|
||||
@@ -319,6 +319,10 @@ async function handleAddNode(
|
||||
}
|
||||
}
|
||||
|
||||
// choose 表达式形态归一化:默认与设计器产出一致(多一个右花括号),可切换为配平形态
|
||||
const chooseMode = resolveChooseSerialization(parsed);
|
||||
normalizeNodeExpressionFields(extra, chooseMode);
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
@@ -351,11 +355,15 @@ async function handleAddNode(
|
||||
extra: Object.keys(extra).length ? extra : undefined,
|
||||
});
|
||||
|
||||
const appPreflight = await preflightNodeAppRequirements(runtime, [
|
||||
newTask as unknown as Record<string, any>,
|
||||
]);
|
||||
|
||||
const saveResult = await saveNodeChanges(client, detail, updatedWorkflow, platformId);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ success: true, pipelineId, newTask, workflow: saveResult }, runtime.outputOptions),
|
||||
stdout: printJson({ success: true, pipelineId, newTask, workflow: saveResult, appRequirementAlerts: appPreflight.alerts }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -372,6 +380,7 @@ async function handleAddNode(
|
||||
"节点总数": String(saveResult.tasks?.length || updatedWorkflow.tasks?.length || 0),
|
||||
"工作流版本": formatWorkflowVersion(saveResult),
|
||||
}),
|
||||
renderAppRequirementAlerts(appPreflight.alerts),
|
||||
].join("\n");
|
||||
|
||||
return { stdout: `${out}\n`, stderr: "", exitCode: 0 };
|
||||
@@ -445,6 +454,10 @@ async function handleEditNode(
|
||||
}
|
||||
}
|
||||
|
||||
// choose 表达式形态归一化:默认与设计器产出一致(多一个右花括号),可切换为配平形态
|
||||
const chooseMode = resolveChooseSerialization(parsed);
|
||||
normalizeNodeExpressionFields(customSet, chooseMode);
|
||||
|
||||
const mappingFile = stringOption(parsed.options, ["mapping-file", "mapping", "json-file"]);
|
||||
if (mappingFile) {
|
||||
const fs = await import("fs/promises");
|
||||
@@ -488,11 +501,15 @@ async function handleEditNode(
|
||||
});
|
||||
const descManaged = desc !== undefined && isServerManagedDescType(editedTask.type);
|
||||
|
||||
const appPreflight = await preflightNodeAppRequirements(runtime, [
|
||||
editedTask as unknown as Record<string, any>,
|
||||
]);
|
||||
|
||||
const saveResult = await saveNodeChanges(client, detail, updatedWorkflow, platformId);
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult, descIgnored: descManaged }, runtime.outputOptions),
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult, descIgnored: descManaged, appRequirementAlerts: appPreflight.alerts }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -510,7 +527,7 @@ async function handleEditNode(
|
||||
: "";
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n${codeTip}${labelTip}${descTip}`,
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n${codeTip}${labelTip}${descTip}${renderAppRequirementAlerts(appPreflight.alerts)}`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
preflightNodeAppRequirements,
|
||||
renderAppRequirementAlerts,
|
||||
type NodeAppRequirementAlert,
|
||||
} from "./shared.js";
|
||||
|
||||
const BACKLOG_URL =
|
||||
"https://wx2.ekuaibao.com/api/openapi/v1/backlog/data/[@{choose('{\"key\":\"webhook_1\"}')}]";
|
||||
|
||||
const noCorpRuntime = { selectedCorp: undefined } as any;
|
||||
|
||||
function alert(overrides: Partial<NodeAppRequirementAlert> = {}): NodeAppRequirementAlert {
|
||||
return {
|
||||
taskName: "action_pyrg",
|
||||
taskLabel: "提交审批",
|
||||
apiName: "单据审批(执行单据动作:同意 / 驳回 / 加签)",
|
||||
appName: "单据审批",
|
||||
powerCode: "TICKET_AUDIT_switch",
|
||||
productId: "o0hMBw000000g0",
|
||||
staticPath: "/api/openapi/v1/backlog/data/[",
|
||||
verified: true,
|
||||
unlicensed: true,
|
||||
message: "节点 [提交审批] (action_pyrg) 调用单据审批,但当前企业尚未开通该应用。",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("保存期应用权限预检", () => {
|
||||
it("非 HTTP 节点不触发任何检查", async () => {
|
||||
const result = await preflightNodeAppRequirements(noCorpRuntime, [
|
||||
{ name: "action_code", type: "code-js2", code: `return "${BACKLOG_URL}";` },
|
||||
]);
|
||||
expect(result.alerts).toEqual([]);
|
||||
expect(result.verifyError).toBeUndefined();
|
||||
});
|
||||
|
||||
it("URL 无法静态判断(上游节点拼接)时不产生告警", async () => {
|
||||
const result = await preflightNodeAppRequirements(noCorpRuntime, [
|
||||
{ name: "action_dyn", type: "http", method: "POST", url: "@{choose('{\"key\":\"action_prev.url\"}')}" },
|
||||
]);
|
||||
expect(result.alerts).toEqual([]);
|
||||
});
|
||||
|
||||
it("命中接口但读不到企业清单 → verified=false,且不阻断", async () => {
|
||||
const result = await preflightNodeAppRequirements(noCorpRuntime, [
|
||||
{ name: "action_pyrg", type: "http", method: "POST", url: BACKLOG_URL },
|
||||
]);
|
||||
expect(result.alerts).toHaveLength(1);
|
||||
const item = result.alerts[0]!;
|
||||
expect(item.verified).toBe(false);
|
||||
expect(item.unlicensed).toBe(false);
|
||||
expect(item.powerCode).toBe("TICKET_AUDIT_switch");
|
||||
expect(item.productId).toBe("o0hMBw000000g0");
|
||||
expect(item.staticPath).toBe("/api/openapi/v1/backlog/data/[");
|
||||
expect(item.message).toContain("未能读取企业应用清单");
|
||||
expect(result.verifyError).toContain("未选择企业");
|
||||
});
|
||||
|
||||
it("非 http 与 http 混排时只检查 http 节点", async () => {
|
||||
const result = await preflightNodeAppRequirements(noCorpRuntime, [
|
||||
{ name: "trigger", type: "webhook", url: BACKLOG_URL },
|
||||
{ name: "action_pyrg", type: "http", method: "POST", url: BACKLOG_URL },
|
||||
null,
|
||||
]);
|
||||
expect(result.alerts.map((item) => item.taskName)).toEqual(["action_pyrg"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("预检结果渲染", () => {
|
||||
it("无告警时输出空串,不污染正常输出", () => {
|
||||
expect(renderAppRequirementAlerts([])).toBe("");
|
||||
});
|
||||
|
||||
it("未开通 → ⛔ 段并带判定依据路径", () => {
|
||||
const text = renderAppRequirementAlerts([alert()]);
|
||||
expect(text).toContain("⛔ 应用权限预检未通过");
|
||||
expect(text).toContain("action_pyrg");
|
||||
expect(text).toContain("判定依据: URL 静态路径 '/api/openapi/v1/backlog/data/['");
|
||||
expect(text).not.toContain("⚠️");
|
||||
});
|
||||
|
||||
it("未核对 → ⚠️ 段,不出现 ⛔", () => {
|
||||
const text = renderAppRequirementAlerts([
|
||||
alert({ verified: false, unlicensed: false, message: "节点 [提交审批] 未能读取企业应用清单" }),
|
||||
]);
|
||||
expect(text).toContain("⚠️ 应用权限未能核对");
|
||||
expect(text).not.toContain("⛔");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,12 @@
|
||||
import { flattenExecutionTree, listAllWorkflows } from "../../../domains/platform/workflow/services.js";
|
||||
import {
|
||||
DEFAULT_CHOOSE_SERIALIZATION,
|
||||
normalizeChooseTags,
|
||||
type ChooseSerialization,
|
||||
} from "../../../domains/platform/workflow/models/choose-serialization.js";
|
||||
import { loadGlobalConfig } from "../../../core/config/loader.js";
|
||||
import { matchAppRequirement } from "../../../domains/platform/workflow/analysis/openapi-app-requirements.js";
|
||||
import { fetchOpenedPowerCodes } from "../../../domains/store/tools.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
|
||||
import type { CliParsedArgs, CliRuntime } from "../../types.js";
|
||||
@@ -171,3 +179,152 @@ export function formatCodeNodeSummariesCard(
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
// ── choose 表达式序列化模式 ────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 解析本轮写入使用的 choose 序列化模式。
|
||||
*
|
||||
* 优先级:命令行 --choose-serialization > 全局配置 chooseSerialization > 默认 frontend。
|
||||
*
|
||||
* 说明:该模式只影响 CLI 往服务端写入的字节形态,读取侧永远同时容忍两种形态。
|
||||
* 详细背景见 src/domains/platform/workflow/models/choose-serialization.ts 顶部注释。
|
||||
*/
|
||||
export function resolveChooseSerialization(parsed: CliParsedArgs): ChooseSerialization {
|
||||
const explicit = stringOption(parsed.options, ["choose-serialization"]);
|
||||
if (explicit === "frontend" || explicit === "pure") {
|
||||
return explicit;
|
||||
}
|
||||
return loadGlobalConfig().chooseSerialization ?? DEFAULT_CHOOSE_SERIALIZATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化对象中所有形如 `url` 的字段(目前只有 http 节点的 `url`),
|
||||
* 让 CLI 写出的结果与设计器保持一致。
|
||||
*/
|
||||
export function normalizeNodeExpressionFields(
|
||||
target: Record<string, any>,
|
||||
mode: ChooseSerialization
|
||||
): { changed: boolean; before?: string; after?: string } {
|
||||
if (!target || typeof target.url !== "string") return { changed: false };
|
||||
const normalized = normalizeChooseTags(target.url, mode);
|
||||
if (normalized === target.url) return { changed: false };
|
||||
const before = target.url;
|
||||
target.url = normalized;
|
||||
return { changed: true, before, after: normalized };
|
||||
}
|
||||
|
||||
// ── 保存期:接口所需企业应用的自动开通状态预检 ──────────────────────────────
|
||||
|
||||
export interface NodeAppRequirementAlert {
|
||||
taskName: string;
|
||||
taskLabel: string;
|
||||
/** 接口的人类可读名称 */
|
||||
apiName: string;
|
||||
/** 所需应用名称 */
|
||||
appName: string;
|
||||
powerCode: string;
|
||||
productId?: string;
|
||||
/** 静态路径(判断依据) */
|
||||
staticPath: string;
|
||||
/** 是否真的读到了企业应用清单 */
|
||||
verified: boolean;
|
||||
/** 已核对且确认未开通 */
|
||||
unlicensed: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存节点时的权限预检:只看**本次写入的节点**,命中已知「接口 → 应用」映射时
|
||||
* 去应用商店核对企业是否已开通。
|
||||
*
|
||||
* 边界(与静态分析保持一致):
|
||||
* - 只处理 http 节点;
|
||||
* - URL 读不出静态路径(整体由上游节点变量拼接)时直接跳过,不猜测;
|
||||
* - 读不到企业应用清单时降级为「无法确认」,不阻断保存。
|
||||
*
|
||||
* 读清单失败不会抛错,也不会卡住写入 —— 这是提示性检查,不是门禁。
|
||||
*/
|
||||
export async function preflightNodeAppRequirements(
|
||||
runtime: CliRuntime,
|
||||
tasks: Array<Record<string, any> | undefined | null>
|
||||
): Promise<{ alerts: NodeAppRequirementAlert[]; verifyError?: string }> {
|
||||
const candidates: Array<{
|
||||
task: Record<string, any>;
|
||||
matched: NonNullable<ReturnType<typeof matchAppRequirement>>;
|
||||
}> = [];
|
||||
|
||||
for (const task of tasks) {
|
||||
if (!task || typeof task !== "object") continue;
|
||||
if (String(task.type || "").trim().toLowerCase() !== "http") continue;
|
||||
const matched = matchAppRequirement(task.url, task.method);
|
||||
if (matched) candidates.push({ task, matched });
|
||||
}
|
||||
if (!candidates.length) return { alerts: [] };
|
||||
|
||||
let opened: Set<string> | undefined;
|
||||
let verifyError: string | undefined;
|
||||
try {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("当前未选择企业");
|
||||
opened = await fetchOpenedPowerCodes(corp);
|
||||
} catch (error) {
|
||||
verifyError = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
|
||||
const alerts = candidates.map(({ task, matched }) => {
|
||||
const { requirement, staticPath } = matched;
|
||||
const verified = opened !== undefined;
|
||||
const unlicensed = verified && !opened!.has(requirement.powerCode.trim().toLowerCase());
|
||||
const taskName = String(task.name || "");
|
||||
const taskLabel = String(task.label || task.displayName || "");
|
||||
const where = requirement.productId
|
||||
? `「${requirement.appName}」(productId=${requirement.productId})`
|
||||
: `「${requirement.appName}」`;
|
||||
const head = `节点 [${taskLabel || taskName}] (${taskName}) 调用 ${requirement.apiName},需要应用${where},powerCode=${requirement.powerCode}`;
|
||||
|
||||
const message = !verified
|
||||
? `${head};未能读取企业应用清单(${verifyError}),请自行到应用商店确认已开通,否则运行时会返回 403。`
|
||||
: unlicensed
|
||||
? `${head},但当前企业尚未开通该应用。流程跑到这个节点必然返回 403「未开通功能,无权访问」,请先到应用商店开通再发布。`
|
||||
: `${head},企业已开通 ✅`;
|
||||
|
||||
return {
|
||||
taskName,
|
||||
taskLabel,
|
||||
apiName: requirement.apiName,
|
||||
appName: requirement.appName,
|
||||
powerCode: requirement.powerCode,
|
||||
productId: requirement.productId,
|
||||
staticPath,
|
||||
verified,
|
||||
unlicensed,
|
||||
message,
|
||||
};
|
||||
});
|
||||
|
||||
return { alerts, verifyError };
|
||||
}
|
||||
|
||||
/** 把预检结果渲染成命令行提示块;无告警时返回空串。 */
|
||||
export function renderAppRequirementAlerts(alerts: NodeAppRequirementAlert[]): string {
|
||||
if (!alerts.length) return "";
|
||||
const lines: string[] = [];
|
||||
const blocked = alerts.filter((a) => a.unlicensed);
|
||||
if (blocked.length) {
|
||||
lines.push("");
|
||||
lines.push("⛔ 应用权限预检未通过(发布后运行到这里必然 403):");
|
||||
for (const alert of blocked) {
|
||||
lines.push(` • ${alert.message}`);
|
||||
lines.push(` 判定依据: URL 静态路径 '${alert.staticPath}'`);
|
||||
}
|
||||
}
|
||||
const unknown = alerts.filter((a) => !a.verified);
|
||||
for (const alert of unknown) {
|
||||
lines.push("");
|
||||
lines.push(`⚠️ 应用权限未能核对:${alert.message}`);
|
||||
lines.push(` 判定依据: URL 静态路径 '${alert.staticPath}'`);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user