feat: 收口多品牌与模板构建基础

This commit is contained in:
que01 committed 2026-09-25 02:55:46 +08:00
1 parent 0425a1c672
commit 77224ea51f
317 files changed
+11290 -1158

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
export const TEMPLATE_RUNTIME_CONTRACT = "1.0" as const;
export type TemplatePageKey =
"home" | "offerings" | "detail" | "inquiry" | "success" | "records" | "profile" | (string & {});
export type TemplateRenderers = Partial<Record<"home" | "offerings" | "profile", string>>;
export type TemplateRuntimeOwnedPage = "detail" | "inquiry" | "success" | "records";
export type TemplatePackageManifest = {
packageKey: string;
version: string;
displayName: string;
runtimeContract: typeof TEMPLATE_RUNTIME_CONTRACT;
supportedIndustryTemplates: string[];
entrypoints: Record<string, string>;
navigation: Array<{
key: string;
label: string;
page: TemplatePageKey;
iconPath?: string;
selectedIconPath?: string;
}>;
requiredCapabilities: string[];
renderers?: TemplateRenderers;
runtimeOwnedPages?: TemplateRuntimeOwnedPage[];
ownedPaths?: string[];
};
export function validateTemplatePackageManifest(value: unknown): string[] {
const errors: string[] = [];
if (!value || typeof value !== "object") return ["manifest must be an object"];
const manifest = value as Partial<TemplatePackageManifest>;
if (!manifest.packageKey?.trim()) errors.push("packageKey is required");
if (!manifest.version?.trim()) errors.push("version is required");
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
errors.push(`runtimeContract must be ${TEMPLATE_RUNTIME_CONTRACT}`);
if (!manifest.displayName?.trim()) errors.push("displayName is required");
if (
!Array.isArray(manifest.supportedIndustryTemplates) ||
!manifest.supportedIndustryTemplates.length
)
errors.push("supportedIndustryTemplates must not be empty");
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
errors.push("navigation must not be empty");
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
errors.push("ownedPaths must be an array when provided");
if (
manifest.renderers !== undefined &&
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
)
errors.push("renderers must be an object when provided");
for (const page of [
"home",
"offerings",
"detail",
"inquiry",
"success",
"records",
"profile",
] as const) {
if (!manifest.entrypoints || typeof manifest.entrypoints[page] !== "string")
errors.push(`entrypoints.${page} is required`);
}
return errors;
}