feat: 能力插件元数据与运行时消费闭环
This commit is contained in:
1 parent
076c6124c8
commit
bb0709b8cc
26 files changed
+2188
-267
No files matched your search
@@ -13,6 +13,33 @@ export interface CapabilityDefinition {
|
||||
workflowKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityDisablePolicy = "allowed" | "disabled";
|
||||
|
||||
export interface CapabilityMetadata {
|
||||
displayName: string;
|
||||
description: string;
|
||||
impact: string;
|
||||
optional: boolean;
|
||||
disablePolicy: CapabilityDisablePolicy;
|
||||
allowedPages: readonly string[];
|
||||
requiredModules: readonly string[];
|
||||
purposeBindings: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityConfigFieldKey = "entryLabel" | "submitHint" | "disabledHint";
|
||||
|
||||
export interface CapabilityConfigField {
|
||||
key: CapabilityConfigFieldKey;
|
||||
label: string;
|
||||
input: "text";
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface CapabilityMetadataDefinition extends CapabilityMetadata {
|
||||
configFields: readonly CapabilityConfigField[];
|
||||
}
|
||||
|
||||
export const workflowRegistry = {
|
||||
"booking.basic": {
|
||||
key: "booking.basic",
|
||||
@@ -29,11 +56,84 @@ export const workflowRegistry = {
|
||||
} as const satisfies Record<string, WorkflowDefinition>;
|
||||
|
||||
export const capabilityRegistry = {
|
||||
offerings: { key: "offerings", version: "1.0.0" },
|
||||
inquiry: { key: "inquiry", version: "1.0.0" },
|
||||
offerings: {
|
||||
key: "offerings",
|
||||
version: "1.0.0",
|
||||
displayName: "业务提供项",
|
||||
description: "展示品牌的服务与产品。",
|
||||
impact: "停用会移除业务提供项展示入口。",
|
||||
optional: false,
|
||||
disablePolicy: "disabled",
|
||||
allowedPages: ["home", "offerings", "detail"],
|
||||
requiredModules: ["offering-list", "offering-detail"],
|
||||
purposeBindings: [],
|
||||
},
|
||||
inquiry: {
|
||||
key: "inquiry",
|
||||
version: "1.0.0",
|
||||
displayName: "通用咨询",
|
||||
description: "接收客户的一对一合作咨询。",
|
||||
impact: "停用后所有通用咨询表单都无法提交。",
|
||||
optional: false,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
booking: { key: "booking", version: "1.0.0", workflowKey: "booking.basic" },
|
||||
"quote-request": { key: "quote-request", version: "1.0.0" },
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition>;
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
version: "1.0.0",
|
||||
displayName: "报价咨询",
|
||||
description: "可选安装的报价请求链路。",
|
||||
impact: "安装后可提交报价咨询;移除后报价表单不再接收提交。",
|
||||
optional: true,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition & Partial<CapabilityMetadata>>;
|
||||
|
||||
export const capabilityConfigFields = {
|
||||
entryLabel: { key: "entryLabel", label: "入口文案", input: "text", required: false },
|
||||
submitHint: { key: "submitHint", label: "提交提示", input: "text", required: false },
|
||||
disabledHint: { key: "disabledHint", label: "停用提示", input: "text", required: false },
|
||||
} as const satisfies Record<CapabilityConfigFieldKey, CapabilityConfigField>;
|
||||
|
||||
export function capabilityMetadata(key: CapabilityKey): CapabilityMetadataDefinition | null {
|
||||
const definition = capabilityRegistry[key];
|
||||
if (!("disablePolicy" in definition)) return null;
|
||||
return { ...definition, configFields: Object.values(capabilityConfigFields) };
|
||||
}
|
||||
|
||||
export function validateCapabilityConfig(
|
||||
capabilityKey: CapabilityKey,
|
||||
config: unknown,
|
||||
): Record<string, string> | null {
|
||||
if (config === undefined || config === null) return {};
|
||||
if (typeof config !== "object" || Array.isArray(config)) return null;
|
||||
const metadata = capabilityMetadata(capabilityKey);
|
||||
if (!metadata) return {};
|
||||
const source = config as Record<string, unknown>;
|
||||
if (Object.keys(source).some((key) => !metadata.configFields.some((field) => field.key === key)))
|
||||
return null;
|
||||
const errors: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(source)) {
|
||||
const field = capabilityConfigFields[key as CapabilityConfigFieldKey];
|
||||
const message =
|
||||
value === undefined || value === null || (typeof value === "string" && !value.trim())
|
||||
? "不能为空"
|
||||
: typeof value !== "string"
|
||||
? "必须是字符串"
|
||||
: value.length > 80
|
||||
? "不能超过 80 个字符"
|
||||
: "";
|
||||
if (message) errors[key] = `${field?.label ?? key}${message}`;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const capabilityPlugins = {
|
||||
inquiry: {
|
||||
@@ -44,6 +144,8 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.inquiry.v1",
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
@@ -53,5 +155,6 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.quote-request.v1",
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const;
|
||||
Reference in new issue
Block a user