Add Webhook integration CLI management
This commit is contained in:
1 parent
48d20a788f
commit
32149762c9
10 files changed
+755
-14
No files matched your search
+128
@@ -11,6 +11,7 @@ import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js";
|
||||
import { getMe } from "./domains/seal/api.js";
|
||||
import { sealTools, type SealTool } from "./domains/seal/tools.js";
|
||||
import { CorpConfig } from "./core/config/types.js";
|
||||
import type { WebhookMode } from "./domains/seal/types.js";
|
||||
import { clearCorpTokenCache } from "./core/auth/token-store.js";
|
||||
import { getHoseProvisionalAuthLink } from "./core/auth/hose.js";
|
||||
import { VERSION } from "./version.js";
|
||||
@@ -254,6 +255,96 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((area === "webhook" || area === "webhooks") && action === "list") {
|
||||
await runTool("seal_webhook_list", client, corp, {
|
||||
query: stringOption(args.options.query) ?? stringOption(args.options.keyword),
|
||||
includeSecret: webhookShowSecretOption(args.options)
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((area === "webhook" || area === "webhooks") && (action === "get" || action === "find")) {
|
||||
const selector = maybeName ?? stringOption(args.options.selector) ?? stringOption(args.options.id);
|
||||
if (!selector) throw new Error("Usage: seal-home webhook get <idOrName> [--show-secret]");
|
||||
await runTool("seal_webhook_get", client, corp, {
|
||||
selector,
|
||||
includeSecret: webhookShowSecretOption(args.options)
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((area === "webhook" || area === "webhooks") && (action === "add" || action === "create")) {
|
||||
const name = stringOption(args.options.name) ?? maybeName;
|
||||
const outgoingResultWebhook =
|
||||
stringOption(args.options.resultUrl) ??
|
||||
stringOption(args.options["result-url"]) ??
|
||||
stringOption(args.options.outgoingResultWebhook) ??
|
||||
stringOption(args.options["outgoing-result-webhook"]);
|
||||
if (!name || !outgoingResultWebhook) {
|
||||
throw new Error("Usage: seal-home webhook add --name <name> --result-url <url> [--mode assisted|semi_automatic|fully_automatic]");
|
||||
}
|
||||
const autoApprovalRate = webhookRateOption(args.options);
|
||||
await runTool("seal_webhook_add", client, corp, {
|
||||
name,
|
||||
mode: parseWebhookMode(stringOption(args.options.mode)),
|
||||
outgoingResultWebhook,
|
||||
autoApprovalRate,
|
||||
secret: stringOption(args.options.secret)
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((area === "webhook" || area === "webhooks") && action === "update") {
|
||||
const selector = maybeName ?? stringOption(args.options.selector) ?? stringOption(args.options.id);
|
||||
if (!selector) throw new Error("Usage: seal-home webhook update <idOrName> [options]");
|
||||
const secret = stringOption(args.options.secret);
|
||||
const rotateSecret = booleanOption(args.options.rotateSecret) ?? booleanOption(args.options["rotate-secret"]);
|
||||
if (secret !== undefined && rotateSecret) {
|
||||
throw new Error("Use either --secret or --rotate-secret, not both");
|
||||
}
|
||||
const name = stringOption(args.options.name);
|
||||
const mode = parseWebhookMode(stringOption(args.options.mode));
|
||||
const outgoingResultWebhook =
|
||||
stringOption(args.options.resultUrl) ??
|
||||
stringOption(args.options["result-url"]) ??
|
||||
stringOption(args.options.outgoingResultWebhook) ??
|
||||
stringOption(args.options["outgoing-result-webhook"]);
|
||||
const autoApprovalRate = webhookRateOption(args.options);
|
||||
if (
|
||||
name === undefined &&
|
||||
mode === undefined &&
|
||||
outgoingResultWebhook === undefined &&
|
||||
autoApprovalRate === undefined &&
|
||||
secret === undefined &&
|
||||
!rotateSecret
|
||||
) {
|
||||
throw new Error("Webhook update requires at least one field option");
|
||||
}
|
||||
await runTool("seal_webhook_update", client, corp, {
|
||||
selector,
|
||||
name,
|
||||
mode,
|
||||
outgoingResultWebhook,
|
||||
autoApprovalRate,
|
||||
secret,
|
||||
rotateSecret
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((area === "webhook" || area === "webhooks") && action === "delete") {
|
||||
const selector = maybeName ?? stringOption(args.options.selector) ?? stringOption(args.options.id);
|
||||
if (!selector) throw new Error("Usage: seal-home webhook delete <idOrName> --yes");
|
||||
if (booleanOption(args.options.yes) !== true) {
|
||||
throw new Error("Refusing to delete Webhook integration without --yes");
|
||||
}
|
||||
await runTool("seal_webhook_delete", client, corp, {
|
||||
selector,
|
||||
confirm: true
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "context") {
|
||||
await runTool("seal_approval_context_get", client, corp, {
|
||||
documentLimit: numberOption(args.options.documentLimit),
|
||||
@@ -1190,6 +1281,38 @@ function splitOption(value: string | boolean | undefined): string[] | undefined
|
||||
return items.length ? items : undefined;
|
||||
}
|
||||
|
||||
function parseWebhookMode(value?: string): WebhookMode | undefined {
|
||||
if (!value) return undefined;
|
||||
const normalized = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
||||
const aliases: Record<string, WebhookMode> = {
|
||||
assisted: "assisted",
|
||||
辅助: "assisted",
|
||||
semi_automatic: "semi_automatic",
|
||||
半自动: "semi_automatic",
|
||||
fully_automatic: "fully_automatic",
|
||||
全自动: "fully_automatic"
|
||||
};
|
||||
const mode = aliases[normalized];
|
||||
if (!mode) {
|
||||
throw new Error("Invalid Webhook mode. Use assisted, semi_automatic, or fully_automatic");
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
function webhookRateOption(options: Record<string, string | boolean>): number | undefined {
|
||||
const value = numberOption(
|
||||
options.autoApprovalRate ?? options["auto-approval-rate"] ?? options["approval-rate"]
|
||||
);
|
||||
if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > 100)) {
|
||||
throw new Error("Webhook auto approval rate must be an integer between 0 and 100");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function webhookShowSecretOption(options: Record<string, string | boolean>): boolean | undefined {
|
||||
return booleanOption(options.showSecret) ?? booleanOption(options["show-secret"]);
|
||||
}
|
||||
|
||||
function booleanOption(value: string | boolean | undefined): boolean | undefined {
|
||||
if (value === undefined) return undefined;
|
||||
if (typeof value === "boolean") return value;
|
||||
@@ -1245,6 +1368,11 @@ Usage:
|
||||
seal-home billing status [--corp <corpId>]
|
||||
seal-home billing plans [--corp <corpId>]
|
||||
seal-home billing features [--corp <corpId>]
|
||||
seal-home webhook list [--query <text>] [--show-secret] [--corp <corpId>]
|
||||
seal-home webhook get|find <idOrName> [--show-secret] [--corp <corpId>]
|
||||
seal-home webhook add --name <name> --result-url <url> [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>] [--corp <corpId>]
|
||||
seal-home webhook update <idOrName> [--name <name>] [--result-url <url>] [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>|--rotate-secret] [--corp <corpId>]
|
||||
seal-home webhook delete <idOrName> --yes [--corp <corpId>]
|
||||
seal-home source config [--corp <corpId>]
|
||||
seal-home tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
|
||||
seal-home rules count [--corp <corpId>]
|
||||
|
||||
Reference in new issue
Block a user