feat(workflow): 企业可用节点探针、灰度开通收敛与DataLink公式硬规则校验
This commit is contained in:
1 parent
4f0eea5725
commit
0768b94d65
14 files changed
+974
-22
No files matched your search
@@ -202,6 +202,9 @@ hose-use workflow patch wf_01k83y... --file=workflow.json --path=tasks.0.code --
|
||||
hose-use workflow history wf_01k83y... --json # 查看服务端版本快照历史
|
||||
hose-use workflow check --json --fail-on-alert # 扫描错误管道并只提醒新增错误计数
|
||||
hose-use workflow publish wf_01k83y... --yes # 将保存后的工作流发布/启用
|
||||
hose-use workflow nodes # 探查当前企业已开通的工作流节点字典(动作/控制/触发器)
|
||||
hose-use workflow nodes --all # 对照官方 108 个灰度节点清单查看全量开通状态
|
||||
hose-use workflow nodes grant code-js2 # 申请开通灰度节点(支持免密模式或 --password 预留密码管控)
|
||||
hose-use workflow create --name="风险推送" --trigger=webhook --yes # 从零新建工作流 (支持 new, add, 自动分配 Webhook UUID, 强制草稿 state=0)
|
||||
hose-use workflow copy wf_01k83y... --name="监控克隆版" --yes # 复制工作流为新草稿 (支持 cp, clone, 自动重置 Webhook urlPath)
|
||||
hose-use workflow delete wf_01k83y... --yes # 安全删除工作流 (支持 rm, remove, 带 --dry-run 预览)
|
||||
|
||||
@@ -205,6 +205,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"diff-job": "对比两次执行的节点分支与报错发散点",
|
||||
"test": "端到端一键调试单据(替代前端手工调测)",
|
||||
"node": "声明式节点编排与增删改 (list|get|add|edit|rm)",
|
||||
"nodes": "查询企业已开通工作流节点字典或开通灰度节点 (list|grant)",
|
||||
"tail": "实时监听任务派发与节点执行日志流 (watch|follow)",
|
||||
"create": "从零新建工作流草稿",
|
||||
"copy": "复制克隆工作流",
|
||||
@@ -271,7 +272,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"dictionary": "enum",
|
||||
"dict": "enum"
|
||||
},
|
||||
flags: { ...flagList("allow-prod allow-production auto-publish autoPublish detail empty errors f fail fail-on-alert failOnAlert failed failed-only failedOnly follow force force-write forceWrite has-error hasError in-place inPlace includeDetail json none once publish snapshot v value-json valueJson verbose", "boolean"), ...flagList("a after app-id appId b bill body c code code-file container count d data desc description end-time endTime entity execution-logs field file flow flow-code flowCode from i id input input-file insert-after interval job job-id job1 job2 jobA jobB jobId l label log logs max-jobs maxJobs n name node node-id nodeId output output-file outputFile p page page-size pageSize parent parent-id parentId path payload pipeline pipeline-id pipelineId platform-id platformId record s sample sample-id sampleId set size snapshot1 snapshot2 snapshotA snapshotB source start-time startTime state state-file stateFile t target targetName targetPlatformId task taskType third-id thirdId timeout timeout-ms timeoutMs to trigger type value workflowId", "value") }
|
||||
flags: { ...flagList("all allow-prod allow-production auto-publish autoPublish compare detail diff empty errors f fail fail-on-alert failOnAlert failed failed-only failedOnly follow force force-write forceWrite has-error hasError in-place inPlace includeDetail json none once publish snapshot v value-json valueJson verbose", "boolean"), ...flagList("a admin-key adminKey after app-id appId b bill body c code code-file container count d data desc description end-time endTime entity execution-logs field file filter flow flow-code flowCode from i id input input-file insert-after interval job job-id job1 job2 jobA jobB jobId keyword l label log logs max-jobs maxJobs n name node node-id nodeId nodes output output-file outputFile p page page-size pageSize parent parent-id parentId password path payload pipeline pipeline-id pipelineId platform-id platformId pwd query record s sample sample-id sampleId set size snapshot1 snapshot2 snapshotA snapshotB source start-time startTime state state-file stateFile t target targetName targetPlatformId task taskType third-id thirdId timeout timeout-ms timeoutMs to trigger type types value workflowId", "value") }
|
||||
},
|
||||
"bill": {
|
||||
"summary": "单据检索、表单规格诊断与审批动作",
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
import { describe, expect, it, spyOn, afterEach } from "bun:test";
|
||||
import { handleWorkflowCommand } from "./workflow/index.js";
|
||||
import * as services from "../../domains/platform/services.js";
|
||||
import * as api from "../../domains/platform/api.js";
|
||||
import * as helpers from "../helpers.js";
|
||||
import type { CliRuntime } from "../types.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
|
||||
const mockCorp: CorpConfig = {
|
||||
id: "ID01rJEL708iTI",
|
||||
name: "浙江麦瑞克科技有限公司",
|
||||
baseUrl: "https://app.ekuaibao.com",
|
||||
source: "openapi",
|
||||
credentials: {
|
||||
accessToken: "mock-access-token",
|
||||
corpId: "ID01rJEL708iTI",
|
||||
staffId: "ID01rJEL708iTI:RkQ8G8L_eMhI00",
|
||||
appKey: "test-key",
|
||||
appSecurity: "test-security",
|
||||
},
|
||||
};
|
||||
|
||||
const mockRuntime: CliRuntime = {
|
||||
corpContext: {
|
||||
listCorps: () => [mockCorp],
|
||||
getCurrent: () => mockCorp,
|
||||
switchCorp: () => true,
|
||||
resolve: () => mockCorp,
|
||||
} as any,
|
||||
selectedCorp: mockCorp,
|
||||
jsonMode: false,
|
||||
outputOptions: {},
|
||||
};
|
||||
|
||||
describe("CLI - workflow nodes 字典探针与灰度开通测试", () => {
|
||||
let spies: ReturnType<typeof spyOn>[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const spy of spies) {
|
||||
spy.mockRestore();
|
||||
}
|
||||
spies = [];
|
||||
delete process.env.HOSE_ADMIN_PASSWORD;
|
||||
});
|
||||
|
||||
it("workflow nodes: 成功探查当前企业已开通节点字典", async () => {
|
||||
spies.push(
|
||||
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue({} as any),
|
||||
spyOn(services, "getWorkflowAvailableNodes").mockResolvedValue({
|
||||
allTypes: new Set(["http", "code", "condition", "clock"]),
|
||||
actionNodes: [
|
||||
{ name: "http节点", type: "http" },
|
||||
{ name: "代码节点", type: "code" },
|
||||
],
|
||||
controlNodes: [{ name: "条件节点", type: "condition" }],
|
||||
triggerNodes: [{ name: "定时触发", type: "clock" }],
|
||||
})
|
||||
);
|
||||
|
||||
const res = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "nodes",
|
||||
args: [],
|
||||
options: {},
|
||||
raw: ["workflow", "nodes"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("当前企业已开通工作流节点字典 [浙江麦瑞克科技有限公司]");
|
||||
expect(res.stdout).toContain("代码节点 (code)");
|
||||
expect(res.stdout).toContain("已开通节点数");
|
||||
});
|
||||
|
||||
it("workflow nodes --all: 成功输出与 108 个灰度节点对照表", async () => {
|
||||
spies.push(
|
||||
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue({} as any),
|
||||
spyOn(services, "getWorkflowAvailableNodes").mockResolvedValue({
|
||||
allTypes: new Set(["code", "http"]),
|
||||
actionNodes: [{ name: "代码节点", type: "code" }],
|
||||
controlNodes: [],
|
||||
triggerNodes: [],
|
||||
})
|
||||
);
|
||||
|
||||
const res = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "nodes",
|
||||
args: [],
|
||||
options: { all: true },
|
||||
raw: ["workflow", "nodes", "--all"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("工作流节点字典与灰度开通对照 [浙江麦瑞克科技有限公司]");
|
||||
expect(res.stdout).toContain("code-js2");
|
||||
expect(res.stdout).toContain("🔒 未开通");
|
||||
expect(res.stdout).toContain("✅ 已开通");
|
||||
});
|
||||
|
||||
it("workflow nodes --json: 输出机器可读的结构化 JSON", async () => {
|
||||
spies.push(
|
||||
spyOn(helpers, "createPiperClientForCorp").mockResolvedValue({} as any),
|
||||
spyOn(services, "getWorkflowAvailableNodes").mockResolvedValue({
|
||||
allTypes: new Set(["code"]),
|
||||
actionNodes: [{ name: "代码节点", type: "code" }],
|
||||
controlNodes: [],
|
||||
triggerNodes: [],
|
||||
})
|
||||
);
|
||||
|
||||
const jsonRuntime: CliRuntime = { ...mockRuntime, jsonMode: true };
|
||||
const res = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "nodes",
|
||||
args: [],
|
||||
options: {},
|
||||
raw: ["workflow", "nodes", "--json"],
|
||||
},
|
||||
jsonRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
const parsedJson = JSON.parse(res.stdout);
|
||||
expect(parsedJson.corpId).toBe("ID01rJEL708iTI");
|
||||
expect(parsedJson.totalGranted).toBe(1);
|
||||
expect(parsedJson.grantedTypes).toContain("code");
|
||||
});
|
||||
|
||||
it("workflow nodes grant: 免密模式下成功发起灰度节点开通", async () => {
|
||||
const grantSpy = spyOn(api, "grantWorkflowNodesApi").mockResolvedValue({
|
||||
success: true,
|
||||
saved: ["code-js2"],
|
||||
skipped: [],
|
||||
rawMessage: "新开通的节点:code-js2",
|
||||
});
|
||||
spies.push(grantSpy);
|
||||
|
||||
const res = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "nodes",
|
||||
args: ["grant", "code-js2"],
|
||||
options: {},
|
||||
raw: ["workflow", "nodes", "grant", "code-js2"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("灰度节点开通结果 [浙江麦瑞克科技有限公司]");
|
||||
expect(res.stdout).toContain("新开通成功");
|
||||
expect(res.stdout).toContain("code-js2");
|
||||
expect(grantSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
nodes: ["code-js2"],
|
||||
token: "mock-access-token",
|
||||
corpId: "ID01rJEL708iTI",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("workflow nodes grant: 节点名称自动中文归一化 (如 'JS节点(新)' 映射为 'code-js2')", async () => {
|
||||
const grantSpy = spyOn(api, "grantWorkflowNodesApi").mockResolvedValue({
|
||||
success: true,
|
||||
saved: ["code-js2"],
|
||||
skipped: [],
|
||||
rawMessage: "新开通的节点:code-js2",
|
||||
});
|
||||
spies.push(grantSpy);
|
||||
|
||||
const res = await handleWorkflowCommand(
|
||||
{
|
||||
area: "workflow",
|
||||
action: "nodes",
|
||||
args: ["grant", "JS节点(新)"],
|
||||
options: {},
|
||||
raw: ["workflow", "nodes", "grant", "JS节点(新)"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(grantSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
nodes: ["code-js2"],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("workflow nodes grant: 管理员密码保护预留生效 (未提供密码或密码错误被拒绝)", async () => {
|
||||
process.env.HOSE_ADMIN_PASSWORD = "secret_admin_pass";
|
||||
|
||||
// 1. 无密码调用被拒绝
|
||||
expect(
|
||||
services.grantWorkflowNodes(mockCorp, {
|
||||
nodes: ["code-js2"],
|
||||
})
|
||||
).rejects.toThrow("管理员保护");
|
||||
|
||||
// 2. 错误密码调用被拒绝
|
||||
expect(
|
||||
services.grantWorkflowNodes(mockCorp, {
|
||||
nodes: ["code-js2"],
|
||||
password: "wrong_password",
|
||||
})
|
||||
).rejects.toThrow("管理员保护");
|
||||
|
||||
// 3. 正确密码调用放行
|
||||
const grantSpy = spyOn(api, "grantWorkflowNodesApi").mockResolvedValue({
|
||||
success: true,
|
||||
saved: ["code-js2"],
|
||||
skipped: [],
|
||||
rawMessage: "开通成功",
|
||||
});
|
||||
spies.push(grantSpy);
|
||||
|
||||
const result = await services.grantWorkflowNodes(mockCorp, {
|
||||
nodes: ["code-js2"],
|
||||
password: "secret_admin_pass",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
expect(grantSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getWorkflowDetail } from "../../../domains/platform/services.js";
|
||||
import { getWorkflowDetail, getWorkflowAvailableNodes } from "../../../domains/platform/services.js";
|
||||
import {
|
||||
analyzeWorkflow,
|
||||
extractWorkflowSpecificationIds,
|
||||
@@ -30,7 +30,15 @@ export async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime):
|
||||
})
|
||||
);
|
||||
}
|
||||
const result = analyzeWorkflow(detail, { specifications });
|
||||
let availableNodeTypes: Set<string> | undefined;
|
||||
try {
|
||||
const available = await getWorkflowAvailableNodes(client);
|
||||
availableNodeTypes = available.allTypes;
|
||||
} catch {
|
||||
// 离线或受限网络环境下忽略探针失败
|
||||
}
|
||||
|
||||
const result = analyzeWorkflow(detail, { specifications, availableNodeTypes });
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
const diagnosticRows = result.diagnostics.map((item) => [item.severity, item.code, item.path, item.message]);
|
||||
const dependencyRows = result.dependencies.map((item) => [item.path, item.taskType, item.references.join(", ")]);
|
||||
|
||||
@@ -6,20 +6,50 @@ import {
|
||||
addWorkflowTask,
|
||||
editWorkflowTask,
|
||||
removeWorkflowTask,
|
||||
getWorkflowAvailableNodes,
|
||||
grantWorkflowNodes,
|
||||
} from "../../../domains/platform/services.js";
|
||||
import {
|
||||
GRAY_NODES_CATALOG,
|
||||
findGrayNode,
|
||||
} from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { stringOption } 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 { createPiperClientForCorp } from "../../helpers.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "rm", "remove", "delete", "del"]);
|
||||
const CORP_LEVEL_ACTIONS = new Set(["available", "list-available", "catalog", "probe", "grant", "open"]);
|
||||
|
||||
export async function handleNodeCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const isPluralNodes = parsed.action === "nodes";
|
||||
const firstArg = parsed.args[0]?.toLowerCase();
|
||||
|
||||
// 1. 企业级节点字典与灰度开通快捷分支
|
||||
if (firstArg === "grant" || firstArg === "open") {
|
||||
return handleGrantNodes(parsed, runtime);
|
||||
}
|
||||
if (
|
||||
firstArg === "available" ||
|
||||
firstArg === "list-available" ||
|
||||
firstArg === "catalog" ||
|
||||
firstArg === "probe"
|
||||
) {
|
||||
return handleListAvailableNodes(parsed, runtime);
|
||||
}
|
||||
|
||||
// 2. 如果是 `hose-use workflow nodes`(复数)且没有指定具体的 pipelineId
|
||||
const secondArg = parsed.args[1];
|
||||
const isSecondArgPipelineId = secondArg && /^\d{10,}$/.test(secondArg.trim());
|
||||
if (isPluralNodes && (!firstArg || ((firstArg === "list" || firstArg === "ls") && !isSecondArgPipelineId && !parsed.options.id && !parsed.options.pipelineId))) {
|
||||
return handleListAvailableNodes(parsed, runtime);
|
||||
}
|
||||
|
||||
let subAction = "list";
|
||||
let pipelineId = "";
|
||||
let nodeTarget = "";
|
||||
@@ -43,19 +73,22 @@ export async function handleNodeCommand(
|
||||
stderr: [
|
||||
"用法: hose-use workflow node <子命令> <pipelineId> [选项]",
|
||||
"",
|
||||
"子命令:",
|
||||
"子命令 (工作流级别):",
|
||||
" list <pipelineId> 列出工作流所有任务节点 (别名: ls, 默认)",
|
||||
" get <pipelineId> <节点标识> 查看指定节点的完整配置 (别名: show, info)",
|
||||
" add <pipelineId> [选项] 声明式追加或插入新任务节点 (别名: append, insert)",
|
||||
" edit <pipelineId> <节点标识> 定向修改指定节点配置 (别名: update, set)",
|
||||
" rm <pipelineId> <节点标识> 安全移除指定任务节点 (别名: remove, delete)",
|
||||
"",
|
||||
"子命令 (企业灰度节点级别):",
|
||||
" nodes [list] [--all] 列出当前企业已开通的节点字典 (别名: probe, catalog)",
|
||||
" nodes grant <type...> 为当前企业开通灰度节点",
|
||||
"",
|
||||
"示例:",
|
||||
" hose-use workflow nodes",
|
||||
" hose-use workflow nodes --all",
|
||||
" hose-use workflow nodes grant code-js2",
|
||||
" hose-use workflow node list 896398895352487950",
|
||||
" hose-use workflow node get 896398895352487950 action_dx9cci",
|
||||
" hose-use workflow node add 896398895352487950 --type=code-js2 --label='数据清洗' --code='return items;' --yes",
|
||||
" hose-use workflow node edit 896398895352487950 action_dx9cci --label='新清洗逻辑' --yes",
|
||||
" hose-use workflow node rm 896398895352487950 action_dx9cci --yes",
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
@@ -426,3 +459,164 @@ async function handleRemoveNode(
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ── 企业可用节点字典与灰度开通 ──────────────────────────────────────────────
|
||||
|
||||
async function handleListAvailableNodes(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp!;
|
||||
const platformId = stringOption(parsed.options, ["platform-id", "platformId", "app-id", "appId"]) || corp.id;
|
||||
const piperClient = await createPiperClientForCorp(corp, platformId);
|
||||
const available = await getWorkflowAvailableNodes(piperClient);
|
||||
|
||||
const showAll = Boolean(parsed.options.all || parsed.options.compare || parsed.options.diff);
|
||||
const filterKw = (
|
||||
parsed.args[1] ||
|
||||
stringOption(parsed.options, ["keyword", "query", "filter"]) ||
|
||||
""
|
||||
).toLowerCase();
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
const output = {
|
||||
corpId: corp.corpId || corp.id,
|
||||
corpName: corp.name,
|
||||
totalGranted: available.allTypes.size,
|
||||
actionNodesCount: available.actionNodes.length,
|
||||
controlNodesCount: available.controlNodes.length,
|
||||
triggerNodesCount: available.triggerNodes.length,
|
||||
grantedTypes: Array.from(available.allTypes).sort(),
|
||||
catalog: {
|
||||
action: available.actionNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
control: available.controlNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
trigger: available.triggerNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
},
|
||||
};
|
||||
return {
|
||||
stdout: printJson(output, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 渲染人类友好视图
|
||||
if (showAll) {
|
||||
// 对照全量 108 个灰度节点
|
||||
const rows = GRAY_NODES_CATALOG.filter((item) => {
|
||||
if (!filterKw) return true;
|
||||
return (
|
||||
item.displayName.toLowerCase().includes(filterKw) ||
|
||||
item.type.toLowerCase().includes(filterKw)
|
||||
);
|
||||
}).map((item) => {
|
||||
const isGranted = available.allTypes.has(item.type.toLowerCase());
|
||||
const statusText = isGranted ? "✅ 已开通" : "🔒 未开通";
|
||||
return [item.displayName, item.type, item.category || "action", statusText];
|
||||
});
|
||||
|
||||
const output = [
|
||||
`====== 工作流节点字典与灰度开通对照 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"当前企业": `${corp.name} (${corp.corpId || corp.id})`,
|
||||
"已开通节点总数": `${available.allTypes.size} 个`,
|
||||
"灰度对照清单": `${GRAY_NODES_CATALOG.length} 个`,
|
||||
}),
|
||||
"",
|
||||
printTable(["显示名称", "节点类型 (type)", "分组", "开通状态"], rows),
|
||||
"",
|
||||
"提示:",
|
||||
" - 使用 hose-use workflow nodes grant <type> 开通灰度节点 (如: hose-use workflow nodes grant code-js2)",
|
||||
].join("\n");
|
||||
|
||||
return { stdout: output, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
// 简要分组视图
|
||||
const actionList = available.actionNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
const controlList = available.controlNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
const triggerList = available.triggerNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
|
||||
const output = [
|
||||
`====== 当前企业已开通工作流节点字典 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"当前企业": `${corp.name} (${corp.corpId || corp.id})`,
|
||||
"已开通节点数": `${available.allTypes.size} 个 (动作 ${available.actionNodes.length}, 控制 ${available.controlNodes.length}, 触发 ${available.triggerNodes.length})`,
|
||||
}),
|
||||
"",
|
||||
`⚡ 触发器节点 (${available.triggerNodes.length}):`,
|
||||
triggerList || "无",
|
||||
"",
|
||||
`⚙️ 动作节点 (${available.actionNodes.length}):`,
|
||||
actionList || "无",
|
||||
"",
|
||||
`🔀 控制流程节点 (${available.controlNodes.length}):`,
|
||||
controlList || "无",
|
||||
"",
|
||||
"提示:",
|
||||
" - 添加 --all 参数可查看与官方 108 个灰度节点清单的完整开通对照表",
|
||||
" - 使用 hose-use workflow nodes grant <type...> 开通新灰度节点 (如: hose-use workflow nodes grant code-js2)",
|
||||
].join("\n");
|
||||
|
||||
return { stdout: output, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
async function handleGrantNodes(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp!;
|
||||
const rawNodes = parsed.args.slice(1);
|
||||
const optionNodes = stringOption(parsed.options, ["nodes", "node", "type", "types"]);
|
||||
const targetNodes: string[] = [];
|
||||
|
||||
if (optionNodes) {
|
||||
targetNodes.push(...optionNodes.split(/[,,\s]+/).map((s) => s.trim()).filter(Boolean));
|
||||
}
|
||||
for (const arg of rawNodes) {
|
||||
if (arg && !arg.startsWith("-")) {
|
||||
targetNodes.push(...arg.split(/[,,\s]+/).map((s) => s.trim()).filter(Boolean));
|
||||
}
|
||||
}
|
||||
|
||||
if (targetNodes.length === 0) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "错误: 请指定要开通的节点类型 (如: hose-use workflow nodes grant code-js2 或 dify)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const password = stringOption(parsed.options, ["password", "pwd", "admin-key"]);
|
||||
|
||||
const result = await grantWorkflowNodes(corp, {
|
||||
nodes: targetNodes,
|
||||
password,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(result, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const lines = [
|
||||
`====== 灰度节点开通结果 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"申请开通节点": targetNodes.join(", "),
|
||||
"新开通成功": result.saved.length ? result.saved.join(", ") : "无 (已处于开通状态)",
|
||||
"跳过(已开通)": result.skipped.length ? result.skipped.join(", ") : "无",
|
||||
"网关反馈": result.rawMessage || "处理成功",
|
||||
}),
|
||||
"",
|
||||
"✅ 节点权限已生效!工作流设计器与 hose-use workflow analyze 将立即支持该节点。",
|
||||
];
|
||||
|
||||
return {
|
||||
stdout: lines.join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { KyInstance } from "ky";
|
||||
import { AuthenticationError, EkbApiError } from "../../core/errors.js";
|
||||
import ky, { KyInstance } from "ky";
|
||||
import { AuthenticationError, BusinessError, EkbApiError } from "../../core/errors.js";
|
||||
import {
|
||||
PlatformSchema,
|
||||
WorkflowPageSchema,
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
WorkflowExecutionPageSchema,
|
||||
WorkflowExecutionLogSchema,
|
||||
WorkflowDslSchema,
|
||||
WorkflowDslCatalogSchema,
|
||||
StaffSchema,
|
||||
WebhookInfoSchema,
|
||||
WorkflowSampleDataSchema,
|
||||
@@ -325,7 +326,34 @@ export async function listDsl(
|
||||
client: KyInstance
|
||||
): Promise<import("./types.js").WorkflowDsl[]> {
|
||||
const response = await client.get("api/easo/dsl/all");
|
||||
return unwrap(response, z.array(WorkflowDslSchema));
|
||||
const raw = await response.json<any>();
|
||||
const payload = raw?.data ?? raw;
|
||||
if (Array.isArray(payload)) {
|
||||
return payload.map((item) => WorkflowDslSchema.parse(item));
|
||||
}
|
||||
// 若是对象结构,将各分类下的 items 拍平返回
|
||||
const allItems: any[] = [
|
||||
...(payload?.action || []),
|
||||
...(payload?.control || []),
|
||||
...(payload?.trigger || []),
|
||||
];
|
||||
return allItems.map((item) => WorkflowDslSchema.parse(item));
|
||||
}
|
||||
|
||||
export async function listDslCatalog(
|
||||
client: KyInstance
|
||||
): Promise<import("./types.js").WorkflowDslCatalog> {
|
||||
const response = await client.get("api/easo/dsl/all");
|
||||
const raw = await response.json<any>();
|
||||
const payload = raw?.data ?? raw;
|
||||
if (Array.isArray(payload)) {
|
||||
return {
|
||||
action: payload,
|
||||
control: [],
|
||||
trigger: [],
|
||||
};
|
||||
}
|
||||
return WorkflowDslCatalogSchema.parse(payload || {});
|
||||
}
|
||||
|
||||
// ── 员工列表(Piper)──────────────────────────────────────────────────────────
|
||||
@@ -429,4 +457,39 @@ export async function getWorkflowEnumOptions(
|
||||
return unwrap(response, z.array(WorkflowEnumItemSchema));
|
||||
}
|
||||
|
||||
// ── 灰度节点开通网关 ──────────────────────────────────────────────────────────
|
||||
|
||||
export async function grantWorkflowNodesApi(options: {
|
||||
token: string;
|
||||
corpId: string;
|
||||
nodes: string[];
|
||||
baseUrl?: string;
|
||||
}): Promise<import("./types.js").GrantWorkflowNodesResult> {
|
||||
const payload = {
|
||||
token: options.token,
|
||||
corpId: options.corpId,
|
||||
nodes: options.nodes.join(","),
|
||||
...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await ky.post("https://d9jxeccs5j.sealosgzg.site/hose-workflow-node", {
|
||||
json: payload,
|
||||
timeout: 30000,
|
||||
});
|
||||
const json = (await response.json()) as any;
|
||||
const data = json?.data ?? {};
|
||||
return {
|
||||
success: Boolean(json?.success ?? true),
|
||||
saved: Array.isArray(data.saved) ? data.saved : [],
|
||||
skipped: Array.isArray(data.skipped) ? data.skipped : [],
|
||||
rawMessage: json?.msg || json?.message || "",
|
||||
};
|
||||
} catch (err: any) {
|
||||
const message = err?.message || String(err);
|
||||
throw new EkbApiError(`灰度节点开通网关调用失败: ${message}`, "GATEWAY_ERROR", 502);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KyInstance } from "ky";
|
||||
import { CorpConfig } from "../../core/config/types.js";
|
||||
import * as api from "./api.js";
|
||||
import { ValidationError } from "../../core/errors.js";
|
||||
import { PermissionError, ValidationError } from "../../core/errors.js";
|
||||
import { explainConditionBranches } from "./workflow/branch/index.js";
|
||||
import { indexExecutionContexts } from "./execution-context.js";
|
||||
import {
|
||||
@@ -70,7 +70,12 @@ export async function copyWorkflow(
|
||||
(cloned.tasks[0] as any).urlPath = crypto.randomUUID();
|
||||
delete (cloned.tasks[0] as any).sampleId;
|
||||
}
|
||||
return api.copyWorkflow(client, pipelineId, cloned);
|
||||
const result = await api.copyWorkflow(client, pipelineId, cloned);
|
||||
if (options.label && result.label !== options.label) {
|
||||
result.label = options.label;
|
||||
return api.updateWorkflow(client, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export interface CreateWorkflowOptions {
|
||||
@@ -977,4 +982,74 @@ export async function resolveWorkflowEnumOptions(
|
||||
return [];
|
||||
}
|
||||
|
||||
// ── 工作流企业可用节点探针与灰度开通 ──────────────────────────────────────────
|
||||
|
||||
export async function getWorkflowAvailableNodes(
|
||||
client: KyInstance
|
||||
): Promise<import("./types.js").AvailableWorkflowNodes> {
|
||||
const catalog = await api.listDslCatalog(client);
|
||||
const allTypes = new Set<string>();
|
||||
|
||||
for (const item of catalog.action) {
|
||||
if (item.type) allTypes.add(item.type);
|
||||
}
|
||||
for (const item of catalog.control) {
|
||||
if (item.type) allTypes.add(item.type);
|
||||
}
|
||||
for (const item of catalog.trigger) {
|
||||
if (item.type) allTypes.add(item.type);
|
||||
}
|
||||
|
||||
return {
|
||||
allTypes,
|
||||
actionNodes: catalog.action,
|
||||
controlNodes: catalog.control,
|
||||
triggerNodes: catalog.trigger,
|
||||
};
|
||||
}
|
||||
|
||||
export async function grantWorkflowNodes(
|
||||
corp: CorpConfig,
|
||||
options: import("./types.js").GrantWorkflowNodesOptions
|
||||
): Promise<import("./types.js").GrantWorkflowNodesResult> {
|
||||
if (!options.nodes || options.nodes.length === 0) {
|
||||
throw new ValidationError("必须指定至少一个需要开通的节点名称或类型");
|
||||
}
|
||||
|
||||
// 1. 管理员密码保护预留设计
|
||||
const adminPassword = process.env.HOSE_ADMIN_PASSWORD;
|
||||
if (adminPassword) {
|
||||
if (!options.password || options.password !== adminPassword) {
|
||||
throw new PermissionError(
|
||||
"灰度节点开通功能已启用管理员保护,请通过 --password 或配置输入正确的管理员密码"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 节点清洗与归一化(将可能传入的中文名映射为标准的 node type)
|
||||
const { findGrayNode } = await import("./workflow/nodes/gray-nodes-catalog.js");
|
||||
const normalizedNodes = options.nodes.map((node) => {
|
||||
const matched = findGrayNode(node);
|
||||
return matched ? matched.type : node.trim();
|
||||
});
|
||||
|
||||
const token = corp.credentials?.accessToken;
|
||||
const corpId = corp.corpId || corp.credentials?.corpId || corp.id;
|
||||
const baseUrl = corp.baseUrl;
|
||||
|
||||
if (!token) {
|
||||
throw new ValidationError("当前企业缺少 accessToken,无法发起节点开通申请");
|
||||
}
|
||||
|
||||
// 3. 调用开通 API
|
||||
const result = await api.grantWorkflowNodesApi({
|
||||
token,
|
||||
corpId,
|
||||
nodes: normalizedNodes,
|
||||
baseUrl,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export * from "./workflow/index.js";
|
||||
@@ -269,20 +269,31 @@ export const WorkflowDetailSchema = z.object({
|
||||
label: z.string().default(""),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
state: z.number().default(0),
|
||||
debugState: z.number().default(0),
|
||||
runTimes: z.number().default(0),
|
||||
errorTimes: z.number().default(0),
|
||||
state: z.coerce.number().default(0),
|
||||
debugState: z.coerce.number().default(0),
|
||||
runTimes: z.coerce.number().default(0),
|
||||
errorTimes: z.coerce.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.number().default(20),
|
||||
source: z.number().default(0),
|
||||
dataLimit: z.coerce.number().default(20),
|
||||
source: z.coerce.number().default(0),
|
||||
queueJobs: z.boolean().default(false),
|
||||
tasksVersion: z.number().default(0),
|
||||
tasksVersion: z.coerce.number().default(0),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
alarm: WorkflowAlarmSchema.optional(),
|
||||
alarm: z.union([
|
||||
WorkflowAlarmSchema,
|
||||
z.string().transform((val) => {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
return WorkflowAlarmSchema.safeParse(parsed).data ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}),
|
||||
z.null(),
|
||||
]).optional(),
|
||||
inputs: z.array(z.object({ key: z.string(), value: z.any() })).optional(),
|
||||
"$snapshot": z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
}).passthrough();
|
||||
@@ -422,12 +433,58 @@ export const WorkflowExecutionPageSchema = z
|
||||
// ── DSL 配置 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDslSchema = z.object({
|
||||
id: z.string(),
|
||||
id: z.string().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
config: z.record(z.string(), z.any()).default({}),
|
||||
});
|
||||
|
||||
export const WorkflowNodeDefinitionSchema = z
|
||||
.object({
|
||||
id: z.string().nullable().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
groupName: z.string().nullable().optional(),
|
||||
icon: z.string().nullable().optional(),
|
||||
iconColor: z.string().nullable().optional(),
|
||||
remark: z.string().nullable().optional(),
|
||||
platform: z.string().nullable().optional(),
|
||||
version: z.number().nullable().optional(),
|
||||
$json: z.string().nullable().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowNodeDefinition = z.infer<typeof WorkflowNodeDefinitionSchema>;
|
||||
|
||||
export const WorkflowDslCatalogSchema = z
|
||||
.object({
|
||||
action: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
control: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
trigger: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowDslCatalog = z.infer<typeof WorkflowDslCatalogSchema>;
|
||||
|
||||
export interface AvailableWorkflowNodes {
|
||||
allTypes: Set<string>;
|
||||
actionNodes: WorkflowNodeDefinition[];
|
||||
controlNodes: WorkflowNodeDefinition[];
|
||||
triggerNodes: WorkflowNodeDefinition[];
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesOptions {
|
||||
nodes: string[];
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesResult {
|
||||
success: boolean;
|
||||
saved: string[];
|
||||
skipped: string[];
|
||||
rawMessage: string;
|
||||
}
|
||||
|
||||
// ── 员工 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StaffSchema = z.object({
|
||||
|
||||
@@ -18,6 +18,8 @@ hose-use workflow debug <pipelineId> --flow=<单号> --yes
|
||||
hose-use workflow create [--name=<名称>] [--trigger=webhook|clock|datalink|flowform] [--file=<JSON模板>] [--dry-run|--yes]
|
||||
hose-use workflow copy <pipelineId> [--name=<名称>] [--platform-id=<应用ID>] [--dry-run|--yes]
|
||||
hose-use workflow delete <pipelineId> [--dry-run|--yes]
|
||||
hose-use workflow nodes [list] [--all]
|
||||
hose-use workflow nodes grant <type...> [--password=<pwd>]
|
||||
hose-use workflow node list <pipelineId>
|
||||
hose-use workflow node get <pipelineId> <节点name或#序号>
|
||||
hose-use workflow node add <pipelineId> --type=code-js2 --label="清洗" --code="..." [--after=<节点>] [--parent=<容器>] [--dry-run|--yes]
|
||||
@@ -72,3 +74,20 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
- 条件解释支持已声明的比较操作符、嵌套 AND/OR 和循环上下文;缺少证据、不支持的值类型或执行尚未结束时,`evaluation` / `matched` 为 `null`,不据此声称分支判定为 False。
|
||||
- `diff-job` 按父任务路径、循环路径及重复次数配对实例;JSON 节点包含 `instanceKey` / `currentLoopPath`,输出变化也计入差异。
|
||||
- `execution-context.ts` 是条件解释和 Job diff 共用的纯执行实例索引,不负责请求或 CLI 输出。
|
||||
|
||||
## 企业可用节点探针与灰度开通(Nodes Probe & Grant)
|
||||
|
||||
合思微前端(Piper)在进入流程设计器与渲染节点级联选择器时,调用 `GET /api/easo/dsl/all` 获取当前租户真实已开通的节点字典(Action、Control、Trigger):
|
||||
- 前端级联选择器仅会渲染当前企业已开通的节点,未开通节点在界面中完全隐身;
|
||||
- 若工作流在后端配置了当前租户未开通的节点类型,执行 `hose-use workflow analyze` 会触发 `PERMISSION_MISSING_NODE` 阻止性诊断并提示开通命令;
|
||||
- 执行 `hose-use workflow nodes` 查看当前租户已开通的节点字典;
|
||||
- 执行 `hose-use workflow nodes --all` 查看当前企业与官方全量 108 个灰度节点清单的开通状态对照;
|
||||
- 执行 `hose-use workflow nodes grant <type...>` 申请开通灰度节点(内置管理员密码预留设计:未配置环境变量 `HOSE_ADMIN_PASSWORD` 时为免密便捷模式;配置后强制要求 `--password` 授权)。
|
||||
|
||||
## 静态分析器硬规则:DataLink 公式误填拦截
|
||||
|
||||
在 `ekuaibao-datalink-create` / `ekuaibao-datalink-edit` 等业务对象数据写入节点中:
|
||||
- 合思 DataLink 属于底层数据写入节点,**不具备前端表单公式求值引擎**;
|
||||
- 若在字段映射中误填表单公式(如 `AddMonths(...)`、`dateDIF(...)`),公式字符串将被直接传给后端,在强类型转换时触发 `ParseException` 导致流程崩溃;
|
||||
- 静态分析器通过 `MISPLACED_FORMULA_IN_DATALINK_MAPPING` 规则在离线期直接拦截并报出致命错误,引导前置增加代码节点(MVEL/JS)预先求值。
|
||||
|
||||
@@ -19,6 +19,13 @@ const KNOWN_TYPES = new Set([
|
||||
"flow-detail",
|
||||
"code",
|
||||
"code-js2",
|
||||
"apportion",
|
||||
"flow-change-trigger",
|
||||
"datalink-button-trigger",
|
||||
"email",
|
||||
"message",
|
||||
"message-dingtalk",
|
||||
"dmn",
|
||||
"ekuaibao-datalink-filter",
|
||||
"ekuaibao-datalink-create",
|
||||
"ekuaibao-datalink-edit",
|
||||
@@ -212,6 +219,81 @@ function findUnguardedDatalinkEdits(
|
||||
return found;
|
||||
}
|
||||
|
||||
const FORMULA_REGEX =
|
||||
/\b(AddMonths|dateDIF|DATEADD|DATEDIF|IF|SUM|ROUND|INT|TEXT|YEAR|MONTH|DAY)\s*\(/i;
|
||||
|
||||
function checkMisplacedFormulasInDatalink(
|
||||
task: WorkflowTask,
|
||||
path: string,
|
||||
diagnostics: WorkflowDiagnostic[]
|
||||
): void {
|
||||
if (!task.type.includes("datalink")) return;
|
||||
const raw = task as Record<string, unknown>;
|
||||
const inspectTargets: Array<{ key: string; value: unknown }> = [];
|
||||
|
||||
// 1. inspect task.inputs
|
||||
if (Array.isArray(task.inputs)) {
|
||||
for (const inp of task.inputs) {
|
||||
if (inp && typeof inp === "object") {
|
||||
inspectTargets.push({ key: inp.key || (inp as any).name || "input", value: inp.value });
|
||||
}
|
||||
}
|
||||
} else if (raw.inputs && typeof raw.inputs === "object") {
|
||||
for (const [k, v] of Object.entries(raw.inputs as Record<string, unknown>)) {
|
||||
inspectTargets.push({ key: k, value: v });
|
||||
}
|
||||
}
|
||||
|
||||
// 2. inspect task.form / formValues / mapping
|
||||
const formEntries = getTaskFormEntries(task);
|
||||
for (const entry of formEntries) {
|
||||
if (entry.key) {
|
||||
inspectTargets.push({ key: entry.key, value: entry.value });
|
||||
}
|
||||
}
|
||||
|
||||
// 3. inspect raw.mapping / raw.data / raw.jsonMapping
|
||||
if (Array.isArray(raw.mapping)) {
|
||||
for (const m of raw.mapping) {
|
||||
if (m && typeof m === "object") {
|
||||
const item = m as Record<string, unknown>;
|
||||
inspectTargets.push({
|
||||
key: String(item.key || item.target || "field"),
|
||||
value: item.value ?? item.source,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. inspect task.fields / raw.fields (合思业务对象新增/修改字段映射)
|
||||
const fields = (task as any).fields ?? raw.fields;
|
||||
if (Array.isArray(fields)) {
|
||||
for (const f of fields) {
|
||||
if (f && typeof f === "object") {
|
||||
const item = f as Record<string, unknown>;
|
||||
inspectTargets.push({
|
||||
key: String(item.key || item.label || "field"),
|
||||
value: item.value,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const target of inspectTargets) {
|
||||
if (typeof target.value === "string") {
|
||||
const match = target.value.match(FORMULA_REGEX);
|
||||
if (match) {
|
||||
diagnostics.push({
|
||||
severity: "error",
|
||||
code: "MISPLACED_FORMULA_IN_DATALINK_MAPPING",
|
||||
path,
|
||||
message: `DataLink 任务 '${task.label || task.name}' 的字段 '${target.key}' 配置了表单公式 '${match[0]}...'。合思 DataLink 属于底层数据写入节点,不支持前端表单公式求值,传入公式字符串会导致后端强类型解析崩溃 (如 ParseException)。请前置添加【代码节点】计算该值并在此处引用。`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function analyzeWorkflow(
|
||||
detail: WorkflowDetail,
|
||||
options: AnalyzeWorkflowOptions = {}
|
||||
@@ -220,6 +302,15 @@ export function analyzeWorkflow(
|
||||
const dependencies: WorkflowDependency[] = [];
|
||||
const diagnostics: WorkflowDiagnostic[] = [];
|
||||
|
||||
const availableSet: Set<string> | undefined = options.availableNodeTypes
|
||||
? new Set(
|
||||
(Array.isArray(options.availableNodeTypes)
|
||||
? options.availableNodeTypes
|
||||
: Array.from(options.availableNodeTypes)
|
||||
).map((t) => t.trim().toLowerCase())
|
||||
)
|
||||
: undefined;
|
||||
|
||||
if (detail.state === 0) {
|
||||
diagnostics.push({
|
||||
severity: "warning",
|
||||
@@ -262,6 +353,19 @@ export function analyzeWorkflow(
|
||||
});
|
||||
}
|
||||
|
||||
// 诊断:租户节点开通权限校验
|
||||
if (availableSet && availableSet.size > 0 && !availableSet.has(task.type.toLowerCase())) {
|
||||
diagnostics.push({
|
||||
severity: "error",
|
||||
code: "PERMISSION_MISSING_NODE",
|
||||
path,
|
||||
message: `当前企业尚未开通节点类型 '${task.type}',工作流运行时将被合思引擎直接阻断。请先使用 'hose-use workflow nodes grant ${task.type}' 开通灰度权限,或替换为已开通的等价节点。`,
|
||||
});
|
||||
}
|
||||
|
||||
// 诊断:DataLink 字段误填表单公式硬校验
|
||||
checkMisplacedFormulasInDatalink(task, path, diagnostics);
|
||||
|
||||
// 诊断 2: every 循环内 flow-create-task (SKIP) 后跟无状态守卫的 ekuaibao-datalink-edit
|
||||
if (insideEvery && task.type === "flow-create-task") {
|
||||
const onError = (task as Record<string, unknown>).onError as
|
||||
|
||||
@@ -164,5 +164,62 @@ describe("Workflow static analysis", () => {
|
||||
expect(codes).toContain("MISSING_BACKLOG_DATA_BRACKETS");
|
||||
expect(result.diagnostics.find((d) => d.code === "MISSING_BACKLOG_DATA_BRACKETS")?.severity).toBe("warning");
|
||||
});
|
||||
|
||||
it("detects PERMISSION_MISSING_NODE when workflow uses nodes not granted to the enterprise", () => {
|
||||
const wf = {
|
||||
id: "wf-missing-perm",
|
||||
label: "新代码节点测试",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "action_1",
|
||||
type: "code-js2",
|
||||
label: "新版JS节点",
|
||||
code: "return 1;",
|
||||
},
|
||||
],
|
||||
};
|
||||
// 假设企业只开通了 code 和 http,没有开通 code-js2
|
||||
const result = analyzeWorkflow(wf as any, {
|
||||
availableNodeTypes: ["code", "http"],
|
||||
});
|
||||
const missingNodeDiag = result.diagnostics.find(
|
||||
(d) => d.code === "PERMISSION_MISSING_NODE"
|
||||
);
|
||||
expect(missingNodeDiag).toBeDefined();
|
||||
expect(missingNodeDiag?.severity).toBe("error");
|
||||
expect(missingNodeDiag?.message).toContain("code-js2");
|
||||
});
|
||||
|
||||
it("detects MISPLACED_FORMULA_IN_DATALINK_MAPPING when formulas are placed in DataLink fields", () => {
|
||||
const wf = {
|
||||
id: "wf-datalink-formula",
|
||||
label: "台账摊销工作流",
|
||||
state: 1,
|
||||
version: "1",
|
||||
tasks: [
|
||||
{
|
||||
name: "action_create",
|
||||
type: "ekuaibao-datalink-create",
|
||||
label: "新增摊销台账",
|
||||
mapping: [
|
||||
{
|
||||
key: "amortizationMonth",
|
||||
value: "AddMonths(date, 1)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = analyzeWorkflow(wf as any);
|
||||
const formulaDiag = result.diagnostics.find(
|
||||
(d) => d.code === "MISPLACED_FORMULA_IN_DATALINK_MAPPING"
|
||||
);
|
||||
expect(formulaDiag).toBeDefined();
|
||||
expect(formulaDiag?.severity).toBe("error");
|
||||
expect(formulaDiag?.message).toContain("AddMonths");
|
||||
expect(formulaDiag?.message).toContain("代码节点");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,4 +47,5 @@ export interface WorkflowFormSpecLike {
|
||||
|
||||
export interface AnalyzeWorkflowOptions {
|
||||
specifications?: Record<string, WorkflowFormSpecLike | undefined>;
|
||||
availableNodeTypes?: Set<string> | string[];
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
export interface GrayNodeItem {
|
||||
displayName: string;
|
||||
name: string;
|
||||
type: string;
|
||||
category?: "action" | "control" | "trigger" | "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* 合思官方工作流灰度节点清单(共 108 个有效去重条目)
|
||||
* 来源于官方灰度开通对照表
|
||||
*/
|
||||
export const GRAY_NODES_CATALOG: readonly GrayNodeItem[] = [
|
||||
{ displayName: "JS节点(新)", name: "JS节点(新)", type: "code-js2", category: "action" },
|
||||
{ displayName: "重算审批流", name: "重算审批流", type: "recalculate-the-approval-flow", category: "action" },
|
||||
{ displayName: "提示框", name: "提示框", type: "ui-notification", category: "action" },
|
||||
{ displayName: "定时任务节点", name: "定时任务节点", type: "start", category: "trigger" },
|
||||
{ displayName: "推送飞书消息", name: "推送飞书消息", type: "feishu-sendMsg", category: "action" },
|
||||
{ displayName: "飞书消息", name: "飞书消息", type: "message-feishu", category: "action" },
|
||||
{ displayName: "if节点", name: "if节点", type: "if", category: "control" },
|
||||
{ displayName: "http节点", name: "http节点", type: "http", category: "action" },
|
||||
{ displayName: "遍历数组", name: "遍历数组", type: "loop", category: "control" },
|
||||
{ displayName: "循环节点", name: "循环节点", type: "while", category: "control" },
|
||||
{ displayName: "企业微信开放平台获取子部门ID列表", name: "企业微信开放平台获取子部门ID列表", type: "wecom-department", category: "action" },
|
||||
{ displayName: "易桥参数转化", name: "易桥参数转化", type: "eBridge-mapData", category: "action" },
|
||||
{ displayName: "代码节点", name: "代码节点", type: "code", category: "action" },
|
||||
{ displayName: "数据映射", name: "数据映射", type: "mapping", category: "action" },
|
||||
{ displayName: "纷享销客鉴权", name: "纷享销客鉴权", type: "fxiaoke-auth", category: "action" },
|
||||
{ displayName: "纷享销客数据列表", name: "纷享销客数据列表", type: "fxiaoke-list", category: "action" },
|
||||
{ displayName: "NetSuite数据列表", name: "NetSuite数据列表", type: "netsuite-sync", category: "action" },
|
||||
{ displayName: "NetSuite数据创建", name: "NetSuite数据创建", type: "netsuite-create", category: "action" },
|
||||
{ displayName: "易桥鉴权", name: "易桥鉴权", type: "ebridge-auth", category: "action" },
|
||||
{ displayName: "新增业务对象数据", name: "新增业务对象数据", type: "ekuaibao-datalink-create", category: "action" },
|
||||
{ displayName: "定时触发", name: "定时触发", type: "clock", category: "trigger" },
|
||||
{ displayName: "纷享销客触发器", name: "纷享销客触发器", type: "fxiaoke-trigger", category: "trigger" },
|
||||
{ displayName: "到达业务对象数据中的日期时触发", name: "到达业务对象数据中的日期时触发", type: "ekuaibao-datalink-time-trigger", category: "trigger" },
|
||||
{ displayName: "发送邮件", name: "发送邮件", type: "email", category: "action" },
|
||||
{ displayName: "查找业务对象数据", name: "查找业务对象数据", type: "ekuaibao-datalink-filter", category: "action" },
|
||||
{ displayName: "修改业务对象数据", name: "修改业务对象数据", type: "ekuaibao-datalink-edit", category: "action" },
|
||||
{ displayName: "NetSuite数据删除", name: "NetSuite数据删除", type: "netsuite-delete", category: "action" },
|
||||
{ displayName: "薪人薪事触发器", name: "薪人薪事触发器", type: "xrxs-trigger", category: "trigger" },
|
||||
{ displayName: "新增业务对象数据时触发", name: "新增业务对象数据时触发", type: "ekuaibao-datalink-create-trigger", category: "trigger" },
|
||||
{ displayName: "变更业务对象数据时触发", name: "变更业务对象数据时触发", type: "ekuaibao-datalink-change-trigger", category: "trigger" },
|
||||
{ displayName: "单据审批事件触发器", name: "单据审批事件触发器", type: "ekuaibao-flowform-trigger", category: "trigger" },
|
||||
{ displayName: "发送短信", name: "发送短信", type: "message", category: "action" },
|
||||
{ displayName: "webhook触发器", name: "webhook触发器", type: "webhook", category: "trigger" },
|
||||
{ displayName: "对话框", name: "对话框", type: "ui-dialog", category: "action" },
|
||||
{ displayName: "流程日志", name: "流程日志", type: "task-log", category: "action" },
|
||||
{ displayName: "动态节点测试", name: "动态节点测试", type: "task-dynamic-test", category: "action" },
|
||||
{ displayName: "条件节点", name: "条件节点", type: "condition", category: "control" },
|
||||
{ displayName: "OpenAPI", name: "OpenAPI", type: "task-openapi", category: "action" },
|
||||
{ displayName: "终止节点", name: "终止节点", type: "stop", category: "action" },
|
||||
{ displayName: "收集节点", name: "收集节点", type: "context", category: "action" },
|
||||
{ displayName: "到达单据日期时触发", name: "到达单据日期时触发", type: "flow-change-trigger", category: "trigger" },
|
||||
{ displayName: "获取钉钉考勤", name: "获取钉钉考勤", type: "task-dynamic-ding-attendance", category: "action" },
|
||||
{ displayName: "摊销节点", name: "摊销节点", type: "apportion", category: "control" },
|
||||
{ displayName: "创建单据", name: "创建单据", type: "flow-create-task", category: "action" },
|
||||
{ displayName: "站内信", name: "站内信", type: "message-internet", category: "action" },
|
||||
{ displayName: "钉钉消息", name: "钉钉消息", type: "message-dingtalk", category: "action" },
|
||||
{ displayName: "修改角色", name: "修改角色", type: "role-update", category: "action" },
|
||||
{ displayName: "依次执行", name: "依次执行", type: "every", category: "control" },
|
||||
{ displayName: "查询申请事项详情", name: "查询申请事项详情", type: "ekuaibao-requision-detail", category: "action" },
|
||||
{ displayName: "查询单据详情", name: "查询单据详情", type: "flow-detail", category: "action" },
|
||||
{ displayName: "查询单据历史详情", name: "查询单据历史详情", type: "flow-detail-versioned", category: "action" },
|
||||
{ displayName: "业务对象数据按钮触发", name: "业务对象数据按钮触发", type: "datalink-button-trigger", category: "trigger" },
|
||||
{ displayName: "查找行程数据", name: "查找行程数据", type: "ekuaibao-tmc-datalink-filter", category: "action" },
|
||||
{ displayName: "新增行程数据时触发", name: "新增行程数据时触发", type: "ekuaibao-tmc-datalink-create-trigger", category: "trigger" },
|
||||
{ displayName: "变更行程数据时触发", name: "变更行程数据时触发", type: "ekuaibao-tmc-datalink-change-trigger", category: "trigger" },
|
||||
{ displayName: "到达行程日期时触发", name: "到达行程日期时触发", type: "ekuaibao-tmc-datalink-time-trigger", category: "trigger" },
|
||||
{ displayName: "查询发票", name: "查询发票", type: "ekuaibao-invoice-datalink-filter", category: "action" },
|
||||
{ displayName: "结果输出", name: "结果输出", type: "output", category: "action" },
|
||||
{ displayName: "EBOT触发", name: "EBOT触发", type: "ekuaibao-ebot-trigger", category: "trigger" },
|
||||
{ displayName: "补充发票触发", name: "补充发票触发", type: "other-event-trigger", category: "trigger" },
|
||||
{ displayName: "发票验真", name: "发票验真", type: "invoice-verification", category: "action" },
|
||||
{ displayName: "JS节点", name: "JS节点", type: "code-js", category: "action" },
|
||||
{ displayName: "数据转化", name: "数据转化", type: "data-convert", category: "action" },
|
||||
{ displayName: "新摊销", name: "新摊销", type: "amortization", category: "control" },
|
||||
{ displayName: "数据映射", name: "数据映射", type: "dmn", category: "action" },
|
||||
{ displayName: "查询人员", name: "查询人员", type: "ekuaibao-staff-filter", category: "action" },
|
||||
{ displayName: "查询单据列表", name: "查询单据列表", type: "flow-list", category: "action" },
|
||||
{ displayName: "HAB触发器", name: "HAB触发器", type: "hab-trigger-task", category: "trigger" },
|
||||
{ displayName: "申请事项触发器", name: "申请事项触发器", type: "ekuaibao-requisition-trigger", category: "trigger" },
|
||||
{ displayName: "创建部门", name: "创建部门", type: "department-create", category: "action" },
|
||||
{ displayName: "部门查询", name: "部门查询", type: "department-filter", category: "action" },
|
||||
{ displayName: "新增人员", name: "新增人员", type: "staff-create", category: "action" },
|
||||
{ displayName: "查询随手记列表", name: "查询随手记列表", type: "ekuaibao-ecard-fee-filter", category: "action" },
|
||||
{ displayName: "查询人员详情", name: "查询人员详情", type: "ekuaibao-staff-detail", category: "action" },
|
||||
{ displayName: "查询部门详情", name: "查询部门详情", type: "ekuaibao-department-detail", category: "action" },
|
||||
{ displayName: "查询易商卡申请事项列表", name: "查询易商卡申请事项列表", type: "ekuaibao-ecard-requisition-filter", category: "action" },
|
||||
{ displayName: "查询飞书部门", name: "查询飞书部门", type: "feishu-department-filter", category: "action" },
|
||||
{ displayName: "修改部门", name: "修改部门", type: "ekuaibao-department-update", category: "action" },
|
||||
{ displayName: "站外信", name: "站外信", type: "message-outnet", category: "action" },
|
||||
{ displayName: "AI节点", name: "AI节点", type: "ekb-ai", category: "action" },
|
||||
{ displayName: "修改单据", name: "修改单据", type: "flow-update-task", category: "action" },
|
||||
{ displayName: "提取文本(word,PDF)", name: "提取文本(word,PDF)", type: "ekb-ai-pdf", category: "action" },
|
||||
{ displayName: "单据风险写入", name: "单据风险写入", type: "risk", category: "action" },
|
||||
{ displayName: "天润工单查询", name: "天润工单查询", type: "tr-select", category: "action" },
|
||||
{ displayName: "天润工单评论", name: "天润工单评论", type: "tr-comment", category: "action" },
|
||||
{ displayName: "天润工单查询详情", name: "天润工单查询详情", type: "tr-detail", category: "action" },
|
||||
{ displayName: "Dify接入", name: "Dify接入", type: "dify", category: "action" },
|
||||
{ displayName: "图片URL识别", name: "图片URL识别", type: "ekb-ai-url", category: "action" },
|
||||
{ displayName: "AI文本理解", name: "AI文本理解", type: "ekb-minimax-text", category: "action" },
|
||||
{ displayName: "AI图像理解", name: "AI图像理解", type: "ekb-minimax-photo", category: "action" },
|
||||
{ displayName: "查询角色下的人员", name: "查询角色下的人员", type: "search-staff-by-role", category: "action" },
|
||||
{ displayName: "发票巡检", name: "发票巡检", type: "ekuaibao-invoice-inspector", category: "action" },
|
||||
{ displayName: "招商银行商务卡查询", name: "招商银行商务卡查询", type: "task-zs", category: "action" },
|
||||
{ displayName: "单据查询详情(跨租户)", name: "单据查询详情(跨租户)", type: "escape", category: "action" },
|
||||
{ displayName: "海亮单据查询详情", name: "海亮单据查询详情", type: "hl-detail", category: "action" },
|
||||
{ displayName: "单据查询详情AI审批专用", name: "单据查询详情AI审批专用", type: "mapping-detail", category: "action" },
|
||||
{ displayName: "海亮数据集列表", name: "海亮数据集列表", type: "hl", category: "action" },
|
||||
{ displayName: "查询易商卡流水的费用信息", name: "查询易商卡流水的费用信息", type: "ekuaibao-ecard-fee-detail-filter", category: "action" },
|
||||
{ displayName: "Ebot审批", name: "Ebot审批", type: "ebot-approval-flow", category: "action" },
|
||||
{ displayName: "给OA账号发送提醒", name: "给OA账号发送提醒", type: "oa", category: "action" },
|
||||
{ displayName: "查询历史单据测试集", name: "查询历史单据测试集", type: "flow-sample-list", category: "action" },
|
||||
{ displayName: "分类汇总", name: "分类汇总", type: "aggregation", category: "action" },
|
||||
{ displayName: "单据转译节点", name: "单据转译节点", type: "flow-format", category: "action" },
|
||||
{ displayName: "导出表格", name: "导出表格", type: "excel", category: "action" },
|
||||
{ displayName: "AI附件理解", name: "AI附件理解", type: "ai-attachment", category: "action" },
|
||||
{ displayName: "AI智能匹配", name: "AI智能匹配", type: "ai-classification", category: "action" },
|
||||
{ displayName: "AI智能提取", name: "AI智能提取", type: "ai-extraction", category: "action" },
|
||||
{ displayName: "延迟执行节点", name: "延迟执行节点", type: "task-dynamic-delay", category: "action" },
|
||||
];
|
||||
|
||||
const typeMap = new Map<string, GrayNodeItem>();
|
||||
const nameMap = new Map<string, GrayNodeItem>();
|
||||
|
||||
for (const item of GRAY_NODES_CATALOG) {
|
||||
typeMap.set(item.type.toLowerCase(), item);
|
||||
nameMap.set(item.displayName.toLowerCase(), item);
|
||||
}
|
||||
|
||||
export function findGrayNode(query: string): GrayNodeItem | undefined {
|
||||
const q = query.trim().toLowerCase();
|
||||
return typeMap.get(q) || nameMap.get(q);
|
||||
}
|
||||
|
||||
export function isKnownGrayNodeType(type: string): boolean {
|
||||
return typeMap.has(type.trim().toLowerCase());
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * from "./types.js";
|
||||
export * from "./tree.js";
|
||||
export * from "./locator.js";
|
||||
export * from "./mutations.js";
|
||||
export * from "./gray-nodes-catalog.js";
|
||||
Reference in new issue
Block a user