v2.6.0: 接入不再自动建 catch-all 邮箱(手动添加);删除账号/域名时清理 Cloudflare 侧资源(关闭 Email Routing + 删除 Email Worker,尽力而为+告警)

This commit is contained in:
bigcode
2026-10-01 02:19:30 +08:00
parent 830ca85ebd
commit c4b5e65159
9 changed files with 350 additions and 39 deletions
+17 -1
View File
@@ -41,6 +41,8 @@ export interface CfMockOptions {
emailRoutingStatusAfterEnable?: string;
/** emailRoutingStatusAfterEnable=misconfigured 时状态对象里的 errors **/
routingErrors?: { code?: string; existing?: { content?: string }; missing?: { content?: string } }[];
/** 删除清理(POST .../routing/disable、DELETE .../workers/scripts/*)返回失败,测告警降级路径 **/
teardownError?: "disable" | "worker";
}
/** # 成员变量: Cloudflare API 桩句柄 **/
@@ -169,6 +171,15 @@ export function installCloudflareMock(opts: CfMockOptions = {}): CfMock {
// PUT / PATCH .../email/routing -> 回 success:true 但 enabled 原封不动(纯回显)
// 2026-09-30 线上正是因为信了 PUT 的返回值,把没开成 Email Routing 的域名标成了「已配置」,
// 表现为域名显示配好了却收不到邮件、Dashboard 邮件路由里也找不到它。
if (url.endsWith("/email/routing/disable")) {
// 关闭 Email Routing 与 enable 同理只有 POST 真生效
if (method !== "POST") return jsonError([{ code: 10405, message: "Method not allowed" }], 405);
if (opts.teardownError === "disable") {
return jsonError([{ code: 10000, message: "email routing disable not permitted" }], 400);
}
state.emailRoutingEnabled = false;
return json({ id: url.split("/").at(-3), enabled: false, status: "disabled" });
}
if (url.endsWith("/email/routing/enable")) {
if (method !== "POST") {
return jsonError(
@@ -199,7 +210,12 @@ export function installCloudflareMock(opts: CfMockOptions = {}): CfMock {
if (url.includes("/dns_records")) return json(opts.foreignMx ?? []);
return json(zones);
}
if (url.includes("/workers/scripts/")) return json({ id: url.split("/").pop() });
if (url.includes("/workers/scripts/")) {
if (method === "DELETE" && opts.teardownError === "worker") {
return jsonError([{ code: 10000, message: "workers.delete not permitted" }], 400);
}
return json({ id: url.split("/").pop() });
}
return json(null, 404);
}) as typeof globalThis.fetch;