feat: 输出统一运行时工作空间契约
This commit is contained in:
1 parent
40b08b5e1d
commit
f9ca5b1fea
4 files changed
+138
-8
No files matched your search
@@ -21,6 +21,7 @@
|
|||||||
"@nestjs/core": "^11.0.11",
|
"@nestjs/core": "^11.0.11",
|
||||||
"@nestjs/platform-fastify": "^11.0.11",
|
"@nestjs/platform-fastify": "^11.0.11",
|
||||||
"@personal-brand/config": "workspace:^",
|
"@personal-brand/config": "workspace:^",
|
||||||
|
"@personal-brand/types": "workspace:^",
|
||||||
"@personal-brand/validation": "workspace:^",
|
"@personal-brand/validation": "workspace:^",
|
||||||
"@prisma/client": "^6.2.1",
|
"@prisma/client": "^6.2.1",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
|
|||||||
+131
-6
@@ -42,6 +42,12 @@ import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
|||||||
import { getBrandTemplate, resolveCapabilities } from "@personal-brand/config";
|
import { getBrandTemplate, resolveCapabilities } from "@personal-brand/config";
|
||||||
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
||||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||||
|
import type {
|
||||||
|
RuntimeInquiryField,
|
||||||
|
RuntimeOffering,
|
||||||
|
RuntimeWorkspace,
|
||||||
|
RuntimeModule,
|
||||||
|
} from "@personal-brand/types";
|
||||||
|
|
||||||
@Controller("health")
|
@Controller("health")
|
||||||
export class HealthController {
|
export class HealthController {
|
||||||
@@ -132,15 +138,93 @@ export class PublicWorkspaceController {
|
|||||||
]);
|
]);
|
||||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
||||||
const template = getBrandTemplate(templateKey);
|
const template = getBrandTemplate(templateKey);
|
||||||
const runtimeModules = modules.map((module) => ({
|
const runtimeModules: RuntimeModule[] = modules.map((module) => ({
|
||||||
key: module.type,
|
key: module.type,
|
||||||
type: module.type,
|
type: this.moduleType(module.type),
|
||||||
title: module.title,
|
version: "1.0.0",
|
||||||
schemaVersion: "1.0",
|
propsSchema: `module.${module.type}.v1`,
|
||||||
sortOrder: module.sortOrder,
|
dataSource: module.type,
|
||||||
config: module.config,
|
config: this.jsonObject(module.config),
|
||||||
|
source:
|
||||||
|
module.source === "custom" ? "custom" : module.source === "template" ? "template" : "core",
|
||||||
}));
|
}));
|
||||||
|
const runtimeOfferings: RuntimeOffering[] = offerings.map((item) => {
|
||||||
|
const config = this.jsonObject(item.config);
|
||||||
|
const sections = Array.isArray(config.sections) ? config.sections : [];
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
summary: item.summary ?? item.description ?? "",
|
||||||
|
enabled: item.isEnabled,
|
||||||
|
schemaKey: typeof config.schemaKey === "string" ? config.schemaKey : "offering.default",
|
||||||
|
schemaVersion: typeof config.schemaVersion === "string" ? config.schemaVersion : "1.0.0",
|
||||||
|
sections: sections
|
||||||
|
.filter((section): section is Record<string, unknown> =>
|
||||||
|
Boolean(section && typeof section === "object"),
|
||||||
|
)
|
||||||
|
.map((section) => ({
|
||||||
|
key: typeof section.key === "string" ? section.key : "section",
|
||||||
|
type: this.sectionType(section.type),
|
||||||
|
config: this.jsonObject(section.config),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const inquiryFields: RuntimeInquiryField[] = this.jsonArray(
|
||||||
|
inquiryForm?.fieldsSnapshot,
|
||||||
|
).flatMap((field) => {
|
||||||
|
if (!field || typeof field !== "object") return [];
|
||||||
|
const value = field as Record<string, unknown>;
|
||||||
|
if (typeof value.key !== "string" || typeof value.label !== "string") return [];
|
||||||
|
const type = [
|
||||||
|
"text",
|
||||||
|
"tel",
|
||||||
|
"number",
|
||||||
|
"select",
|
||||||
|
"radio",
|
||||||
|
"checkbox",
|
||||||
|
"textarea",
|
||||||
|
"date",
|
||||||
|
].includes(String(value.type))
|
||||||
|
? (value.type as RuntimeInquiryField["type"])
|
||||||
|
: "text";
|
||||||
|
return [{ key: value.key, label: value.label, type, required: value.required === true }];
|
||||||
|
});
|
||||||
|
const runtimeWorkspace: RuntimeWorkspace = {
|
||||||
|
schemaVersion: "1.0.0",
|
||||||
|
brand: (brand ?? {}) as Record<string, unknown>,
|
||||||
|
navigation: {
|
||||||
|
tabs: [
|
||||||
|
{ key: "home", label: "首页", page: "pages/index/index" },
|
||||||
|
{ key: "offerings", label: "案例与体系", page: "pages/services/index" },
|
||||||
|
{ key: "profile", label: "主理人与我", page: "pages/bookings/index" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
modules: runtimeModules,
|
||||||
|
offerings: runtimeOfferings,
|
||||||
|
inquiryForms: inquiryForm
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
key: inquiryForm.id,
|
||||||
|
version: String(inquiryForm.version),
|
||||||
|
purpose: this.formPurpose(inquiryForm.purpose),
|
||||||
|
target: inquiryForm.targetType === "offering" ? "offering" : "brand",
|
||||||
|
submissionAction: this.submissionAction(inquiryForm.submissionAction),
|
||||||
|
fields: inquiryFields,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
capabilities: (template ? resolveCapabilities(template.capabilities) : []).map(
|
||||||
|
(capability) => ({
|
||||||
|
key: capability.key,
|
||||||
|
version: capability.version,
|
||||||
|
config: {},
|
||||||
|
status: "enabled" as const,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
theme: { colors: { background: "#F7F5F1", foreground: "#252525", accent: "#8A6846" } },
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
|
...runtimeWorkspace,
|
||||||
contractVersion: "1.0",
|
contractVersion: "1.0",
|
||||||
brand,
|
brand,
|
||||||
template: template
|
template: template
|
||||||
@@ -159,6 +243,47 @@ export class PublicWorkspaceController {
|
|||||||
inquiryForm,
|
inquiryForm,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
private jsonObject(value: unknown): Record<string, unknown> {
|
||||||
|
return value && typeof value === "object" && !Array.isArray(value)
|
||||||
|
? (value as Record<string, unknown>)
|
||||||
|
: {};
|
||||||
|
}
|
||||||
|
private jsonArray(value: unknown): Prisma.JsonValue[] {
|
||||||
|
return Array.isArray(value) ? value : [];
|
||||||
|
}
|
||||||
|
private moduleType(value: string): RuntimeModule["type"] {
|
||||||
|
const known: RuntimeModule["type"][] = [
|
||||||
|
"brand-hero",
|
||||||
|
"founder-card",
|
||||||
|
"trust-proof",
|
||||||
|
"offering-list",
|
||||||
|
"offering-detail",
|
||||||
|
"gallery",
|
||||||
|
"timeline",
|
||||||
|
"faq",
|
||||||
|
"contact",
|
||||||
|
"inquiry",
|
||||||
|
"records",
|
||||||
|
"custom",
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
known.includes(value as RuntimeModule["type"]) ? value : "custom"
|
||||||
|
) as RuntimeModule["type"];
|
||||||
|
}
|
||||||
|
private sectionType(value: unknown): RuntimeOffering["sections"][number]["type"] {
|
||||||
|
const known = ["text", "image-list", "timeline", "faq", "specification"] as const;
|
||||||
|
return known.includes(value as (typeof known)[number])
|
||||||
|
? (value as (typeof known)[number])
|
||||||
|
: "text";
|
||||||
|
}
|
||||||
|
private formPurpose(value: string): RuntimeWorkspace["inquiryForms"][number]["purpose"] {
|
||||||
|
return value === "booking" || value === "quote-request" ? value : "inquiry";
|
||||||
|
}
|
||||||
|
private submissionAction(
|
||||||
|
value: string,
|
||||||
|
): RuntimeWorkspace["inquiryForms"][number]["submissionAction"] {
|
||||||
|
return value === "create-booking" || value === "create-quote" ? value : "create-inquiry";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Controller("public/offerings")
|
@Controller("public/offerings")
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
- [x] 新增共享 `TemplateManifest`、`ModuleManifest`、`CapabilityManifest` 类型。
|
- [x] 新增共享 `TemplateManifest`、`ModuleManifest`、`CapabilityManifest` 类型。
|
||||||
- [x] 新增 `RuntimeWorkspace`、Offering、Inquiry 和 Capability 运行时类型。
|
- [x] 新增 `RuntimeWorkspace`、Offering、Inquiry 和 Capability 运行时类型。
|
||||||
- [x] 新增模板声明的基础校验函数。
|
- [x] 新增模板声明的基础校验函数。
|
||||||
- [ ] 在 API 增加运行时工作空间 DTO 和公开接口。
|
- [x] 在 API 增加运行时工作空间公开接口字段(`/public/workspace`)。
|
||||||
|
- [x] API 工作空间输出统一导航、模块、Offering、表单和能力结构。
|
||||||
- [ ] 增加 API 授权、品牌隔离和 schema 版本测试。
|
- [ ] 增加 API 授权、品牌隔离和 schema 版本测试。
|
||||||
- [ ] 让 Admin 与小程序读取同一运行时契约。
|
- [ ] 让 Admin 与小程序读取同一运行时契约。
|
||||||
|
|
||||||
@@ -33,4 +34,4 @@
|
|||||||
|
|
||||||
## 当前交付门槛
|
## 当前交付门槛
|
||||||
|
|
||||||
在 Phase 1 的 API 契约、测试和客户端消费完成前,不新增第二个行业页面,也不继续扩展行业专属固定 WXML。
|
在 Phase 1 的 API 契约、测试和客户端消费完成前,不新增第二个行业页面,也不继续扩展行业专属固定 WXML。当前 API 契约已建立,下一步优先补测试和客户端消费。
|
||||||
Generated
+3
@@ -78,6 +78,9 @@ importers:
|
|||||||
'@personal-brand/config':
|
'@personal-brand/config':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../../packages/config
|
version: link:../../packages/config
|
||||||
|
'@personal-brand/types':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../../packages/types
|
||||||
'@personal-brand/validation':
|
'@personal-brand/validation':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../../packages/validation
|
version: link:../../packages/validation
|
||||||
|
|||||||
Reference in new issue
Block a user