98 lines
4.4 KiB
TypeScript
98 lines
4.4 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { runTool } from "../helpers.js";
|
|
import { jsonObject, stringOption } from "../parser.js";
|
|
import { outputOptions } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleDeployCommand(
|
|
systemOrAction: string | undefined,
|
|
actionOrTarget: string | undefined,
|
|
maybeTarget: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
if (!systemOrAction || systemOrAction === "help") {
|
|
throw new Error(
|
|
"Usage: seal-use deploy <system> <action> [options]\n\n" +
|
|
"支持的审批系统与发布目标:\n" +
|
|
" • hosecloud (合思费控): seal-use deploy hosecloud <requirements|list|get|status|configure|sync> --corp <corpId>\n" +
|
|
" • webhook (通用审批流回调): seal-use webhook <list|get|add|update|delete> --corp <corpId>\n" +
|
|
" • feishu (飞书审批): 建议使用 Webhook 模式对接\n" +
|
|
" • weaver (泛微 OA): 建议使用 Webhook 模式对接\n" +
|
|
" • helios (汇联易): 建议使用 Webhook 模式对接\n" +
|
|
" • maycur (每刻报销): 建议使用 Webhook 模式对接"
|
|
);
|
|
}
|
|
|
|
if (systemOrAction === "webhook" || systemOrAction === "webhooks") {
|
|
throw new Error("Webhook 审批流发布请直接使用专有命令:seal-use webhook <list|get|add|update|delete> --corp <corpId>");
|
|
}
|
|
|
|
if (systemOrAction === "feishu" || systemOrAction === "lark") {
|
|
throw new Error("飞书审批发布:建议使用 Webhook 通用发布模式对接。命令:seal-use webhook add --name '飞书审批' --result-url <url> --corp <corpId>");
|
|
}
|
|
|
|
if (systemOrAction === "weaver") {
|
|
throw new Error("泛微 OA 发布:建议使用 Webhook 通用发布模式对接。命令:seal-use webhook add --name '泛微OA' --result-url <url> --corp <corpId>");
|
|
}
|
|
|
|
if (systemOrAction === "maycur" || systemOrAction === "helios") {
|
|
const name = systemOrAction === "maycur" ? "每刻报销" : "汇联易";
|
|
throw new Error(`${name}发布:目前可通过 Webhook 模式接入。命令:seal-use webhook add --name '${name}' --result-url <url> --corp <corpId>`);
|
|
}
|
|
|
|
const isHosecloud = systemOrAction === "hosecloud";
|
|
const action = systemOrAction === "hosecloud" ? actionOrTarget : systemOrAction;
|
|
const target = systemOrAction === "hosecloud" ? maybeTarget : actionOrTarget;
|
|
|
|
if (!isHosecloud) {
|
|
throw new Error(`未知的发布目标系统: ${systemOrAction}。当前支持: hosecloud (合思费控) 与 webhook (通用回调)。`);
|
|
}
|
|
|
|
if (action === "requirements") {
|
|
await runTool("seal_deploy_hosecloud_requirements", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "list") {
|
|
await runTool("seal_deploy_hosecloud_list", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "get") {
|
|
const signKey = target ?? stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]);
|
|
if (!signKey) throw new Error("Usage: seal-use deploy hosecloud get <sign-key>");
|
|
await runTool("seal_deploy_hosecloud_get", client, corp, { signKey }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "status") {
|
|
await runTool("seal_deploy_hosecloud_status", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "configure") {
|
|
const rawInput = stringOption(args.options.input);
|
|
const payload = rawInput
|
|
? JSON.parse(readFileSync(rawInput, "utf8"))
|
|
: jsonObject(args.json);
|
|
if (!payload || Object.keys(payload).length === 0) {
|
|
throw new Error("Usage: seal-use deploy hosecloud configure --json '{...}' or --input <file>");
|
|
}
|
|
await runTool("seal_deploy_hosecloud_configure", client, corp, payload, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "sync") {
|
|
const signKey = target ?? stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]);
|
|
if (!signKey) throw new Error("Usage: seal-use deploy hosecloud sync <sign-key>");
|
|
await runTool("seal_deploy_hosecloud_sync", client, corp, { signKey }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown deploy hosecloud action: ${action ?? ""}. Available: requirements, list, get, status, configure, sync.`);
|
|
}
|