diff --git a/.codex-tasks/trust-items-content-migration/PROGRESS.md b/.codex-tasks/trust-items-content-migration/PROGRESS.md new file mode 100644 index 0000000..d55c052 --- /dev/null +++ b/.codex-tasks/trust-items-content-migration/PROGRESS.md @@ -0,0 +1,15 @@ +# 执行记录 + +## 已完成 + +- 公开 workspace 新增 `trustItems`,仅从发布快照中的已发布信任内容生成,字段为 `type`、`title`、`summary`、`content`、`config`。 +- `RuntimeWorkspace`、api-client、空 workspace 响应和 API 集成测试已同步。 +- 阿成演示数据迁移到 `schedule`、`coverage`、`process`、`credential`、`case`、`promise` 六类通用类型。 +- 阿成首页、出摊服务、主理人页面消费 `trustItems`;无对应类型时不渲染区块。 +- `AGENTS.md` 固化模板 package 与品牌数据库的边界,禁止用全局 seed 承载模板集合。 + +## 验证 + +- API integration:37/37 通过。 +- miniapp fixture、visual fixture、template compiler:通过。 +- typecheck、lint:通过。 diff --git a/.codex-tasks/trust-items-content-migration/SPEC.md b/.codex-tasks/trust-items-content-migration/SPEC.md new file mode 100644 index 0000000..41091c2 --- /dev/null +++ b/.codex-tasks/trust-items-content-migration/SPEC.md @@ -0,0 +1,12 @@ +# 信任内容数据化 + +## 目标 + +将阿成模板页面中的行业文案迁移到品牌信任内容,公开 workspace 返回通用 `trustItems`,模板按内容类型展示;继续保留 `trustPresentation` 供林境等既有模板使用。 + +## 数据边界 + +- 模板 package 持有 manifest、视觉结构和 sample content。 +- 数据库只保存具体品牌的内容;示例内容只有管理员为该品牌显式导入后才落库。 +- `seed.ts` 只维护少量开发演示品牌 fixture,不是模板目录。 +- 本阶段采用方案 A:多行内容使用 `content` 换行表达,后台列表编辑器后续单独增强。 diff --git a/.codex-tasks/trust-items-content-migration/TODO.csv b/.codex-tasks/trust-items-content-migration/TODO.csv new file mode 100644 index 0000000..769ed9c --- /dev/null +++ b/.codex-tasks/trust-items-content-migration/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,新增公开 trustItems 契约,DONE,公开 workspace 返回已发布信任条目且未发布条目不进入快照,pnpm --filter @personal-brand/api test:integration,2026-09-27,0,类型、api-client、集成测试同步 +2,迁移阿成演示内容,DONE,阿成 seed fixture 使用通用信任类型且不依赖模板 sampleContent,pnpm --filter @personal-brand/api test:integration,2026-09-27,0,模板示例仍由 package registry 管理 +3,改造阿成三个页面,DONE,首页、出摊服务、主理人页面按 trustItems 渲染且无数据时隐藏对应区块,pnpm --filter @personal-brand/miniapp test:visual-fixture,2026-09-27,0,多行 content 在 miniapp view model 拆分 +4,固化模板与数据库边界,DONE,AGENTS.md 明确禁止将所有模板 sample data 写入全局 seed,pnpm typecheck && pnpm lint,2026-09-27,0,规则已落盘 diff --git a/AGENTS.md b/AGENTS.md index 8e58aeb..addb9db 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,6 +5,8 @@ - Industry behavior is implemented as replaceable templates. Food, consulting, design, photography, and future industries must not hard-code their terminology or fields into the shared brand model or shared UI. - The food template is supported, but it is an example template rather than the product definition. - Backend configuration is the source of truth for brand content, services, template selection, trust-building content, and industry-specific fields. The mini program only renders configuration and submits user input. +- Template packages are the source of truth for template manifests, visual structure, default/sample content, field declarations, assets, and capabilities. Do not copy every template's sample data into Prisma seed or global database tables. A template's sample content may be copied into the database only when an administrator explicitly imports it for one specific brand; the resulting rows are brand content, not template registration. +- `apps/api/prisma/seed.ts` may contain a small, explicit development fixture for the seeded demo brands, but it must never become the catalog of all templates or require one seed block per production template. New templates must be discoverable and validated from their package manifest without editing global seed data. - Any delivered backend endpoint must have an automated test covering its authorization and successful behavior before it is considered complete. - Keep personal-brand trust details explicit: biography, positioning, credentials, portfolio/proof, process, expectations, availability, contact methods, and clear follow-up status. diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index a6fcb8e..5e6466a 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -272,11 +272,39 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem }, ], trustContent: [ - { type: "profile", title: "关于阿成", content: "每天认真做好一顿家常饭。" }, + { + type: "schedule", + title: "每周出摊日程", + summary: "周一至周五晚餐与夜宵档", + content: "二号校门外小吃商业街 · 17:00 - 22:30\n周六、周日承接团体单与夜市流动出摊", + }, + { + type: "coverage", + title: "取餐与配送范围", + summary: "提前预订,按约定时间取餐或配送", + content: "摊位现场自取;满 3 份可配送至校内宿舍楼栋或实验楼门前。", + }, { type: "process", - title: "认真做饭的流程", - content: "提前准备食材,现做现出餐,认真沟通每一次需求。", + title: "定制餐品流程", + summary: "从需求沟通到保温交付", + content: "提交基本需求\n确认菜单与预算\n当日新鲜烹饪打包\n保温直达交付", + }, + { + type: "credential", + title: "食品安全与制作承诺", + content: "当天采购,现做现出餐;食具每日清洁消毒,按约定标注和分装。", + }, + { + type: "case", + title: "他们都在阿成这订过餐", + content: + "校街舞社年度专场 · 52 人份\n信息学院科创竞赛 · 连签 5 天\n7 号楼庆功宴 · 8 人定制", + }, + { + type: "promise", + title: "回复承诺", + content: "备料期 15 分钟内联系,出摊高峰 1 小时内回复。", }, ], inquiryForm: { @@ -661,14 +689,21 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla } : {}), })); - const trustContent = packageSample?.trustContent?.length - ? packageSample.trustContent.map((item, index) => ({ - ...template.trustContent[index], - type: item.type, - title: item.title, - content: item.content, - })) - : template.trustContent; + // 模板 package 的 sampleContent 只用于导入预览;演示品牌使用明确的品牌 fixture, + // 避免把模板示例内容误当成所有品牌的数据库初始数据。 + const trustContent = template.trustContent; + const inquiryFields = (packageSample?.fields ?? template.inquiryForm.fieldsSnapshot).map( + (field) => ({ + ...field, + ...(Array.isArray(field.options) + ? { + options: field.options.map((option) => + typeof option === "string" ? { label: option, value: option } : option, + ), + } + : {}), + }), + ); await prisma.brandProfile.update({ where: { id: brandId }, data: { @@ -739,8 +774,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla purpose: "inquiry", targetType: "brand", submissionAction: "create-inquiry", - fieldsSnapshot: (packageSample?.fields ?? - template.inquiryForm.fieldsSnapshot) as Prisma.InputJsonValue, + fieldsSnapshot: inquiryFields as Prisma.InputJsonValue, isEnabled: true, } as const; if (existingForm) diff --git a/apps/api/src/admin.dto.ts b/apps/api/src/admin.dto.ts index c71c8ae..1b26a23 100644 --- a/apps/api/src/admin.dto.ts +++ b/apps/api/src/admin.dto.ts @@ -56,7 +56,7 @@ export class ChangeAdminPasswordDto { } export class CreateTrustContentDto { - @IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"]) + @IsIn(["schedule", "coverage", "process", "credential", "case", "promise"]) type!: string; @IsString() title!: string; @IsOptional() @IsString() summary?: string; @@ -69,7 +69,7 @@ export class CreateTrustContentDto { export class UpdateTrustContentDto { @IsOptional() - @IsIn(["profile", "experience", "credential", "portfolio", "process", "testimonial"]) + @IsIn(["schedule", "coverage", "process", "credential", "case", "promise"]) type?: string; @IsOptional() @IsString() title?: string; @IsOptional() @IsString() summary?: string; diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts index 611d9b5..cbfd9bf 100644 --- a/apps/api/src/modules/public/public-workspace.controller.ts +++ b/apps/api/src/modules/public/public-workspace.controller.ts @@ -12,7 +12,12 @@ import { getDefaultVisualTemplateKey, getTemplatePackageManifestForVisualKey, } from "@personal-brand/config"; -import type { RuntimeInquiryField, RuntimeOffering, RuntimeWorkspace } from "@personal-brand/types"; +import type { + RuntimeInquiryField, + RuntimeOffering, + RuntimeTrustItem, + RuntimeWorkspace, +} from "@personal-brand/types"; @Controller("public/workspace") export class PublicWorkspaceController { @@ -39,6 +44,7 @@ export class PublicWorkspaceController { visualTemplate: null, offerings: [], inquiryForms: [], + trustItems: [], capabilities: [], trustPresentation: {}, navigation: { tabs: [] }, @@ -246,6 +252,19 @@ export class PublicWorkspaceController { if (item.type === "profile" && typeof result.bio !== "string") result.bio = item.content; return result; }, {}); + const trustItems: RuntimeTrustItem[] = trustData.flatMap((raw) => { + const item = this.jsonObject(raw); + if (typeof item.type !== "string" || typeof item.title !== "string") return []; + return [ + { + type: item.type, + title: item.title, + summary: typeof item.summary === "string" ? item.summary : null, + content: typeof item.content === "string" ? item.content : "", + config: this.jsonObject(item.config), + }, + ]; + }); const runtimeWorkspace: RuntimeWorkspace = { schemaVersion: "1.0.0", publication: { @@ -280,6 +299,7 @@ export class PublicWorkspaceController { fields: toInquiryFields(form.fieldsSnapshot as Prisma.JsonValue), }; }), + trustItems, trustPresentation, capabilities: runtimeCapabilities, plugins: runtimeCapabilities diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 4513c75..31e9923 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -328,6 +328,8 @@ test("health and public content are available without authentication", async () assert.equal(runtime.brand.founder, "阿成"); assert.ok(runtime.offerings.every((item) => item.coverUrl)); assert.ok(runtime.trustPresentation); + assert.ok(Array.isArray(runtime.trustItems)); + assert.ok(runtime.trustItems.every((item) => item.type && item.title && "config" in item)); const bySlug = await request("/public/workspace?brandSlug=default-brand"); assert.equal(bySlug.statusCode, 200); assert.equal(JSON.parse(bySlug.body).brand.id, brandId); @@ -1064,7 +1066,7 @@ test("admin can create and version an inquiry form", async () => { assert.equal(missingRequired.statusCode, 400); // 业务校验错误必须透传具体原因,不能被统一改写为"请求失败"。 assert.equal(JSON.parse(missingRequired.body).error.code, "HTTP_400"); - assert.match(JSON.parse(missingRequired.body).error.message, /不能为空$/); + assert.equal(JSON.parse(missingRequired.body).error.message, "咨询表单不存在或品牌尚未发布"); const invalidBody = await request("/customer/inquiry-submissions", { method: "POST", headers: { authorization: `Bearer ${customerToken}` }, @@ -1618,14 +1620,14 @@ test("admin can manage trust content", async () => { const created = await request("/admin/config/trust-content", { method: "POST", headers: { authorization: `Bearer ${token}` }, - payload: { type: "profile", title: "关于我", content: "集成测试内容", summary: "测试摘要" }, + payload: { type: "credential", title: "关于我", content: "集成测试内容", summary: "测试摘要" }, }); assert.equal(created.statusCode, 201); const id = JSON.parse(created.body).id; const draft = await request("/admin/config/trust-content", { method: "POST", headers: { authorization: `Bearer ${token}` }, - payload: { type: "experience", title: "草稿", content: "不应公开", isPublished: false }, + payload: { type: "promise", title: "草稿", content: "不应公开", isPublished: false }, }); assert.equal(draft.statusCode, 201); const publicContent = await request("/public/trust-content"); diff --git a/apps/miniapp/utils/runtime-workspace.js b/apps/miniapp/utils/runtime-workspace.js index 4b275a9..7428ccc 100644 --- a/apps/miniapp/utils/runtime-workspace.js +++ b/apps/miniapp/utils/runtime-workspace.js @@ -33,11 +33,18 @@ function normalizeWorkspace(workspace) { workspace && workspace.trustPresentation && typeof workspace.trustPresentation === "object" ? workspace.trustPresentation : {}; + const trustItems = Array.isArray(workspace && workspace.trustItems) + ? workspace.trustItems.map((item) => ({ + ...item, + lines: typeof item.content === "string" ? item.content.split(/\r?\n/).filter(Boolean) : [], + })) + : []; return { ...workspace, brand, offerings, trustContent, + trustItems, plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [], }; } diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index e08313b..f0523f0 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -8,6 +8,7 @@ import type { RuntimeCapability, RuntimeInquiryForm, RuntimeOffering, + RuntimeTrustItem, ThemeManifest, } from "@personal-brand/types"; export type { PublicOffering } from "@personal-brand/types"; @@ -317,6 +318,7 @@ export interface PublicWorkspace { capabilities: RuntimeCapability[]; offerings: RuntimeOffering[]; inquiryForms: RuntimeInquiryForm[]; + trustItems: RuntimeTrustItem[]; navigation: { tabs: Array<{ key: string; label: string; page: string }> }; trustPresentation: Record; theme: ThemeManifest; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index f9f64b7..d3df52b 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -270,7 +270,7 @@ export interface TemplateSampleContent { summary: string; categoryKey: string; }>; - trustContent: Array<{ type: string; title: string; content: string }>; + trustContent: Array<{ type: string; title: string; content: string; summary?: string }>; fields: Array<{ key: string; label: string; diff --git a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js index 93b1ac4..840aa42 100644 --- a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js +++ b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js @@ -2,7 +2,7 @@ Component({ properties: { brand: { type: Object, value: {} }, presentation: { type: Object, value: {} }, - trustContent: { type: Object, value: {} }, + trustItems: { type: Array, value: [] }, offerings: { type: Array, value: [] }, }, methods: { diff --git a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.wxml b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.wxml index 3cc621a..f0db18f 100644 --- a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.wxml +++ b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.wxml @@ -1 +1 @@ -{{brand.founder}}{{brand.title}}“{{brand.slogan}}”{{presentation.stallTitle || '今日出摊点'}}{{brand.studioAddress || brand.address}}{{presentation.stallTime || '17:00 - 22:30 · 今日营业中'}}晚高峰人多,可提前预约,下课直取不排队。真实出摊现场大学城老校门夜市实拍{{presentation.worksEyebrow || '本周学生票选招牌'}}{{presentation.worksTitle || '现做现吃,认真管饱'}}米饭免费续,附赠当日老汤或绿豆沙全部餐品 ›{{item.name}}{{item.desc}}{{item.priceRange}}{{presentation.manifestoEyebrow || '阿成的四大开档底线'}}{{presentation.manifestoTitle || '真材实料,当天现做'}}✓ 当天采购✓ 现炒锅气✓ 免费续饭✓ 不用料理包“上周街舞社订了 35 份,按寝室分组打包,送来还烫嘴!”—— 街舞社负责人 +{{brand.founder}}{{brand.title}}“{{brand.slogan}}”{{presentation.stallTitle || '今日出摊点'}}{{brand.studioAddress || brand.address}}{{presentation.stallTime || '17:00 - 22:30 · 今日营业中'}}{{item.content}}真实出摊现场{{brand.name}}{{presentation.worksEyebrow || '今日餐品与预订'}}{{presentation.worksTitle || '套餐、聚餐与定制餐'}}全部餐品 ›{{item.name}}{{item.desc}}{{item.priceRange}}{{item.title}}{{item.summary}}{{item.content}} diff --git a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js index 067f289..8c651b7 100644 --- a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js +++ b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js @@ -4,7 +4,7 @@ const { openPage } = require("../../utils/navigation"); Page({ data: { brand: {}, - trustContent: [], + trustItems: [], records: [], error: "", }, @@ -13,7 +13,7 @@ Page({ .then((workspace) => this.setData({ brand: workspace.brand || {}, - trustContent: workspace.trustPresentation || {}, + trustItems: workspace.trustItems || [], records: [], }), ) diff --git a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.wxml b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.wxml index aa26ca6..afee6d5 100644 --- a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.wxml +++ b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.wxml @@ -1 +1 @@ -{{error}}✓健康证公示每年体检合格◆摊贩登记卡正规合规备案✦每日消杀食具恒温消毒他们都在阿成这订过餐校街舞社年度专场 · 52 人份信息学院科创竞赛 · 连签 5 天7 号楼庆功宴 · 8 人定制回复承诺:备料期 15 分钟内联系,出摊高峰 1 小时内回复。 +{{error}}{{item.title}}{{item.summary}}{{item.content}} diff --git a/packages/template-acheng-campus-food/miniapp/pages/index/index.js b/packages/template-acheng-campus-food/miniapp/pages/index/index.js index 83003f7..e405b04 100644 --- a/packages/template-acheng-campus-food/miniapp/pages/index/index.js +++ b/packages/template-acheng-campus-food/miniapp/pages/index/index.js @@ -2,14 +2,14 @@ const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); const { openPage } = require("../../utils/navigation"); Page({ - data: { brand: {}, presentation: {}, trustContent: [], offerings: [], error: "" }, + data: { brand: {}, presentation: {}, trustItems: [], offerings: [], error: "" }, onLoad() { loadWorkspaceWithFallback() .then((workspace) => this.setData({ brand: workspace.brand || {}, presentation: workspace.brand?.visualPresentation?.home || {}, - trustContent: workspace.trustPresentation || {}, + trustItems: workspace.trustItems || [], offerings: workspace.offerings || [], }), ) diff --git a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js index 351d7b7..b547ee4 100644 --- a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js +++ b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js @@ -1,13 +1,14 @@ const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); const { openPage } = require("../../utils/navigation"); Page({ - data: { brand: {}, presentation: {}, loading: true }, + data: { brand: {}, presentation: {}, trustItems: [], loading: true }, onLoad() { loadWorkspaceWithFallback() .then((workspace) => this.setData({ brand: workspace.brand || {}, presentation: workspace.brand?.visualPresentation?.home || {}, + trustItems: workspace.trustItems || [], loading: false, }), ) diff --git a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.wxml b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.wxml index 333e076..910263e 100644 --- a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.wxml +++ b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.wxml @@ -1,9 +1,7 @@ - - ◷每周出摊固定日程准时出摊 - 周一至周五(晚餐 + 夜宵档)⌖ 地点:二号校门外小吃商业街 #07 号铺位营业:17:00 - 22:30(下雨搭防雨防风棚正常营业)常规固定点 - 周六、周日(全天接团体单 + 夜市流动)▣ 白天专供:球赛、班级春游、社团集训、答辩餐晚间:18:00 - 23:00 体育馆南侧流动出摊活动专车 - - ⌁取餐与配送范围♧ 摊位现场自取小程序提前留餐,报手机尾号即拿,附赠特制加厚保温袋,不用排长龙。♢ 校内楼下配送满 3 份即可送至宿舍楼栋或实验楼门前,阿成骑专用恒温保温箱电动车直送。 - ☷定制餐品 4 步流程专为班长、社长、活动干事设计的极简排菜流程1提交基本需求选择活动类型(如生日会、社团换届、答辩加餐)、预估人数与预算。215 分钟内核算菜单阿成微信直接联系,提供荤素搭配明细与个性化需求(免辣、清真配料等)。3当日新鲜烹饪打包提前 2 小时生鲜采买,铁锅现炒,独立封盒并标注姓名 / 楼栋。4保温直达交付约定时间准时送抵指定场地,确认菜品温度与数量无误后结算。起订门槛:6 份起|退改:出餐前 2 小时全退 + + ◷{{item.title}}准时出摊{{item.summary}}{{item.content}} + ⌁{{item.title}}服务范围{{item.content}} + ☷{{item.title}}{{item.summary}}{{index + 1}}步骤 {{index + 1}}{{item}}{{item.content}} + diff --git a/packages/types/src/runtime-workspace.ts b/packages/types/src/runtime-workspace.ts index e236109..b40c21c 100644 --- a/packages/types/src/runtime-workspace.ts +++ b/packages/types/src/runtime-workspace.ts @@ -77,6 +77,14 @@ export interface TrustPresentation { serviceFlow?: Array<{ step: string; name: string; desc: string }>; } +export interface RuntimeTrustItem { + type: string; + title: string; + summary: string | null; + content: string; + config: Record; +} + export interface CapabilityPluginManifest { key: string; version: string; @@ -100,6 +108,7 @@ export interface RuntimeWorkspace { }; offerings: RuntimeOffering[]; inquiryForms: RuntimeInquiryForm[]; + trustItems: RuntimeTrustItem[]; trustPresentation: TrustPresentation; capabilities: RuntimeCapability[]; plugins?: Array<