feat: 分离模板演示数据并校验预览资源
This commit is contained in:
1 parent
6edde5a8d6
commit
b60174885e
31 files changed
+1785
-69
No files matched your search
@@ -106,3 +106,90 @@ export function validateFieldSnapshot(value: unknown): ValidationIssue[] {
|
||||
export function validateOfferingConfig(value: unknown): ValidationIssue[] {
|
||||
return value === undefined || value === null ? [] : issues(offeringConfigSchema.safeParse(value));
|
||||
}
|
||||
|
||||
// 预览身份采用白名单,联系信息由预览运行时固定为空,不允许导入真实联系人。
|
||||
export const templatePreviewFixtureSchema = z
|
||||
.object({
|
||||
schemaVersion: z.literal("1"),
|
||||
brand: z
|
||||
.object({
|
||||
name: z.string().trim().min(1),
|
||||
tagline: z.string(),
|
||||
description: z.string(),
|
||||
avatarUrl: z.string().optional(),
|
||||
coverUrl: z.string().optional(),
|
||||
hours: z.string().optional(),
|
||||
address: z.string().optional(),
|
||||
deliveryNote: z.string().optional(),
|
||||
})
|
||||
.strict(),
|
||||
content: z
|
||||
.object({
|
||||
templateKey: z.string().min(1),
|
||||
brandConfig: z.record(z.unknown()).optional(),
|
||||
inquiryFormName: z.string().trim().min(1),
|
||||
capabilityKey: z.string().min(1),
|
||||
offerings: z.array(
|
||||
z
|
||||
.object({
|
||||
kind: z.enum(["service", "product", "package", "subscription"]),
|
||||
name: z.string().trim().min(1),
|
||||
summary: z.string(),
|
||||
categoryKey: z.string().min(1),
|
||||
coverUrl: z.string().optional(),
|
||||
priceText: z.string().optional(),
|
||||
config: z.record(z.unknown()).optional(),
|
||||
})
|
||||
.strict(),
|
||||
),
|
||||
trustContent: z.array(
|
||||
z
|
||||
.object({
|
||||
type: z.string().min(1),
|
||||
title: z.string(),
|
||||
content: z.string(),
|
||||
summary: z.string().optional(),
|
||||
config: z.record(z.unknown()).optional(),
|
||||
})
|
||||
.strict(),
|
||||
),
|
||||
fields: fieldSnapshotSchema,
|
||||
})
|
||||
.strict(),
|
||||
safety: z
|
||||
.object({
|
||||
submissions: z.literal("disabled"),
|
||||
customerRecords: z.literal("disabled"),
|
||||
contactActions: z.literal("disabled"),
|
||||
})
|
||||
.strict(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export function validateTemplatePreviewFixture(value: unknown): ValidationIssue[] {
|
||||
return issues(templatePreviewFixtureSchema.safeParse(value));
|
||||
}
|
||||
|
||||
export function validateTemplatePreviewFixtures(
|
||||
value: unknown,
|
||||
industries: readonly string[],
|
||||
): ValidationIssue[] {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value))
|
||||
return [{ path: "", message: "must be an industry map" }];
|
||||
const fixtures = value as Record<string, unknown>;
|
||||
const result: ValidationIssue[] = [];
|
||||
for (const industry of new Set([...industries, ...Object.keys(fixtures)])) {
|
||||
if (!industries.includes(industry))
|
||||
result.push({ path: industry, message: "is not a supported industry template" });
|
||||
const fixture = templatePreviewFixtureSchema.safeParse(fixtures[industry]);
|
||||
result.push(
|
||||
...issues(fixture).map((issue) => ({
|
||||
path: `${industry}.${issue.path}`,
|
||||
message: issue.message,
|
||||
})),
|
||||
);
|
||||
if (fixture.success && fixture.data.content.templateKey !== industry)
|
||||
result.push({ path: `${industry}.content.templateKey`, message: "must match its key" });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user