Organize Seal modules and add guarded rule recoding
This commit is contained in:
1 parent
f788f9c6db
commit
8c7cb219a0
65 files changed
+837
-131
No files matched your search
+21
-1
@@ -10,6 +10,7 @@ import { CorpConfig } from "../../core/config/types.js";
|
||||
import { ensureHoseOpenapiToken, fetchHoseCloseApiToken, defaultSealUrl, normalizeBaseUrl } from "../../core/auth/hose.js";
|
||||
import { createSealClientForUrl } from "../../core/http/factory.js";
|
||||
import { redactSensitiveText } from "../../core/redact.js";
|
||||
import { safetyBlocked } from "../../core/errors.js";
|
||||
import { resolveSealCustomHeaders } from "../../core/http/request-headers.js";
|
||||
import {
|
||||
ApprovalDocumentListData,
|
||||
@@ -140,7 +141,13 @@ export async function deleteApprovalRule(client: KyInstance, ruleId: string): Pr
|
||||
}
|
||||
|
||||
export async function recodeApprovalRules(client: KyInstance): Promise<unknown> {
|
||||
const response = await client.post("api/v1/rules/batch-recode", { throwHttpErrors: false });
|
||||
// Legacy clear/sync callers may reset an EMPTY draft's allocation counter.
|
||||
// Renumbering existing rules must go through the ticketed recode capability.
|
||||
const draft = await listApprovalRules(client);
|
||||
if (draft.rules.length > 0) {
|
||||
throw safetyBlocked("禁止隐式重排非空草稿,请使用 rules recode 的两阶段确认流程。");
|
||||
}
|
||||
const response = await client.post("api/v1/rules/batch-recode", { throwHttpErrors: false, retry: 0 });
|
||||
const body = await response.json().catch(() => ({}));
|
||||
return z.object({
|
||||
ok: z.boolean(),
|
||||
@@ -153,6 +160,19 @@ export async function recodeApprovalRules(client: KyInstance): Promise<unknown>
|
||||
});
|
||||
}
|
||||
|
||||
/** Called only after the shared recode capability consumes its confirmation ticket. */
|
||||
export async function executeApprovalRulesRecode(client: KyInstance) {
|
||||
const response = await client.post("api/v1/rules/batch-recode", { retry: 0 });
|
||||
const body = await response.json() as { data?: unknown };
|
||||
const result = z.object({
|
||||
activeRules: z.number().int().nonnegative(),
|
||||
pendingDeleteRules: z.number().int().nonnegative(),
|
||||
nextCode: z.number().int().nonnegative()
|
||||
}).safeParse(body.data ?? body);
|
||||
if (!result.success) throw new Error("规则重排接口返回了无效结果,请回读当前草稿确认状态。");
|
||||
return result.data;
|
||||
}
|
||||
|
||||
export async function listApprovalRuleVersions(client: KyInstance): Promise<RuleSetVersion[]> {
|
||||
return unwrap(await client.get("api/v1/rule-set-versions"), z.array(RuleSetVersionSchema));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user