refactor: 将模板示例内容移入模板包
This commit is contained in:
1 parent
dd55af8d73
commit
6218ed395b
7 files changed
+517
-18
No files matched your search
@@ -60,6 +60,14 @@ export type TemplateAdminManifest = {
|
||||
sections: TemplateAdminSection[];
|
||||
};
|
||||
|
||||
export type TemplateSampleContent = {
|
||||
templateKey: string;
|
||||
offerings: Array<Record<string, unknown>>;
|
||||
trustContent: Array<Record<string, unknown>>;
|
||||
fields: Array<Record<string, unknown>>;
|
||||
capabilityKey: string;
|
||||
};
|
||||
|
||||
export type TemplatePackageManifest = {
|
||||
packageKey: string;
|
||||
version: string;
|
||||
@@ -81,6 +89,7 @@ export type TemplatePackageManifest = {
|
||||
dataSlots: TemplateDataSlot[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
sampleContent?: Record<string, TemplateSampleContent>;
|
||||
};
|
||||
|
||||
export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
@@ -149,5 +158,25 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
if (!manifest.entrypoints || typeof manifest.entrypoints[page] !== "string")
|
||||
errors.push(`entrypoints.${page} is required`);
|
||||
}
|
||||
if (manifest.sampleContent !== undefined) {
|
||||
for (const [industryKey, sample] of Object.entries(manifest.sampleContent)) {
|
||||
if (!manifest.supportedIndustryTemplates.includes(industryKey))
|
||||
errors.push(`sampleContent.${industryKey} is not a supported industry template`);
|
||||
if (sample.templateKey !== industryKey)
|
||||
errors.push(`sampleContent.${industryKey}.templateKey must match its key`);
|
||||
if (!Array.isArray(sample.offerings) || !Array.isArray(sample.trustContent))
|
||||
errors.push(`sampleContent.${industryKey} requires offerings and trustContent arrays`);
|
||||
if (!Array.isArray(sample.fields) || !sample.fields.length)
|
||||
errors.push(`sampleContent.${industryKey} requires fields`);
|
||||
for (const field of sample.fields ?? []) {
|
||||
if (typeof field.key !== "string" || typeof field.label !== "string")
|
||||
errors.push(`sampleContent.${industryKey} fields require key and label`);
|
||||
if (["select", "radio", "multi-select"].includes(String(field.type))) {
|
||||
if (!Array.isArray(field.options) || !field.options.length)
|
||||
errors.push(`sampleContent.${industryKey}.${String(field.key)} requires options`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
Reference in new issue
Block a user