feat: 接通后台渲染异常上报与响应契约校验
This commit is contained in:
1 parent
330d67adc1
commit
adcaa12970
22 files changed
+845
-33
No files matched your search
@@ -0,0 +1,199 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Admin 列表接口的运行时契约。
|
||||
*
|
||||
* 这些 schema 只用于校验,不参与数据转换:请求层在通过校验后返回原始响应体,
|
||||
* 因此新增字段不会被裁剪。缺少关键字段或字段类型错误时抛出 ApiClientContractError,
|
||||
* 由页面已有的错误态展示,而不是让 React 在渲染阶段崩溃。
|
||||
*/
|
||||
|
||||
const record = z.record(z.string(), z.unknown());
|
||||
const nullableText = z.string().nullish();
|
||||
|
||||
export const adminBrandMembershipListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
role: z.string(),
|
||||
brand: z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
slug: z.string(),
|
||||
templateKey: z.string(),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminBrandMemberListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
role: z.string(),
|
||||
isEnabled: z.boolean(),
|
||||
adminUser: z.object({
|
||||
id: z.string(),
|
||||
username: z.string(),
|
||||
displayName: z.string(),
|
||||
isEnabled: z.boolean(),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminReleaseListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
version: z.number(),
|
||||
status: z.string(),
|
||||
actorId: z.string(),
|
||||
createdAt: z.string(),
|
||||
note: nullableText,
|
||||
revokedAt: nullableText,
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminMiniAppReleaseListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
version: z.number(),
|
||||
status: z.enum([
|
||||
"built",
|
||||
"uploaded",
|
||||
"under_review",
|
||||
"rejected",
|
||||
"approved",
|
||||
"published",
|
||||
"failed",
|
||||
]),
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminTrustContentListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
title: z.string(),
|
||||
content: z.string(),
|
||||
sortOrder: z.number(),
|
||||
isPublished: z.boolean(),
|
||||
summary: nullableText,
|
||||
coverUrl: nullableText,
|
||||
config: record.nullish(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminOfferingListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
kind: z.enum(["service", "product", "package", "subscription"]),
|
||||
name: z.string(),
|
||||
isEnabled: z.boolean(),
|
||||
sortOrder: z.number(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminInquiryFormListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
version: z.number(),
|
||||
isEnabled: z.boolean(),
|
||||
fieldsSnapshot: z.array(z.unknown()),
|
||||
purpose: z.enum(["inquiry", "booking", "quote-request"]),
|
||||
targetType: z.enum(["brand", "offering"]),
|
||||
submissionAction: z.enum(["create-inquiry", "create-booking", "create-quote"]),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminInquirySubmissionListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
inquiryFormId: z.string(),
|
||||
formVersion: z.number(),
|
||||
fieldsSnapshot: z.array(z.unknown()),
|
||||
values: record,
|
||||
activeFields: record,
|
||||
createdAt: z.string(),
|
||||
status: z.enum(["new", "reviewing", "replied", "qualified", "converted", "closed"]),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminBookingListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
bookingNo: z.string(),
|
||||
status: z.enum(["received", "contacting", "confirmed", "completed", "cancelled"]),
|
||||
estimatedAmount: z.number().nullable(),
|
||||
createdAt: z.string(),
|
||||
customerName: z.string(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminBookingTagListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
isPreset: z.boolean(),
|
||||
isEnabled: z.boolean(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminCapabilityListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string().nullable(),
|
||||
capabilityKey: z.string(),
|
||||
capabilityVersion: z.string(),
|
||||
status: z.enum(["enabled", "disabled", "degraded"]),
|
||||
updatedAt: z.string().nullable(),
|
||||
}),
|
||||
);
|
||||
|
||||
const templatePackageVersionSchema = z.object({
|
||||
id: z.string(),
|
||||
templatePackageId: z.string(),
|
||||
packageKey: z.string(),
|
||||
version: z.string(),
|
||||
displayName: z.string(),
|
||||
status: z.enum(["imported", "published", "retired", "disabled"]),
|
||||
contentChecksum: z.string(),
|
||||
archiveChecksum: z.string(),
|
||||
importedAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
validationReport: record,
|
||||
importedBy: z.object({
|
||||
id: z.string(),
|
||||
username: z.string(),
|
||||
displayName: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const adminTemplatePackageListSchema = z.object({
|
||||
items: z.array(templatePackageVersionSchema),
|
||||
page: z.number(),
|
||||
pageSize: z.number(),
|
||||
total: z.number(),
|
||||
});
|
||||
|
||||
export const adminTemplatePackageAuditListSchema = z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
action: z.string(),
|
||||
fromStatus: z.enum(["imported", "published", "retired", "disabled"]).nullish(),
|
||||
toStatus: z.enum(["imported", "published", "retired", "disabled"]).nullish(),
|
||||
requestId: nullableText,
|
||||
createdAt: z.string(),
|
||||
actor: z.object({
|
||||
id: z.string(),
|
||||
username: z.string(),
|
||||
displayName: z.string(),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const adminTemplateOperationFailuresSchema = z.object({
|
||||
since: z.string(),
|
||||
until: z.string(),
|
||||
days: z.number(),
|
||||
backfilled: z.boolean(),
|
||||
failures: z.array(z.object({ action: z.string(), count: z.number() })),
|
||||
});
|
||||
Reference in new issue
Block a user