diff --git a/.codex-tasks/brand-friendly-template-content-epic/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/PROGRESS.md index 1b5e501..4dfa54c 100644 --- a/.codex-tasks/brand-friendly-template-content-epic/PROGRESS.md +++ b/.codex-tasks/brand-friendly-template-content-epic/PROGRESS.md @@ -2,15 +2,16 @@ - 任务:品牌友好内容工作台与模板契约增强 - 形态:epic -- 进度:0/5 -- 当前:任务已建立,等待从模板与 Admin 内容契约开始实施。 +- 进度:5/5 +- 当前:5 个自动化子任务完成,等待用户人工验收;Epic 尚未关闭。 - 真相文件:`SUBTASKS.csv` ## Context Recovery Block -- 当前子任务:#1 模板与 Admin 内容契约 -- 当前状态:TODO -- 已完成:无 +- 当前子任务:最终全量验证 +- 当前状态:自动化完成,待人工验收 +- 已完成:#1 契约、#2 RuntimeWorkspace 投影、#3 发布模板适配校验、#4 品牌友好内容工作台、#5 双模板回归;API 集成测试 37 项通过。 - 关键背景:阿成和林境静态视觉验收通过,但 RuntimeWorkspace、发布校验和 Admin 编辑仍不足以支撑大量差异化模板。 -- 已知问题:后端导航存在固定结构痕迹;offering projection 可能丢失展示属性;公共视觉页面不应再作为模板兜底。 -- 下一步:审计现有模板 manifest、Admin 配置页面和发布服务,定义最小的 Template Admin Contract。 +- 已解决风险:导航和 offering 展示属性按 package 快照投影;Admin 编辑声明仅进入受保护 workspace,public Runtime 不暴露;模板目录指纹校验可发现生成产物过期。 +- 后续事项:Admin production build 的 `api` chunk 约 667 KB,超过 Vite 500 KB 提示线;建议另开 Admin 路由级代码拆分任务,本 Epic 不以此阻塞验收。 +- 下一步:用户验收阿成/林境 Admin 品牌表达页及发布体验;按反馈修订后再关闭 Epic。自动化验证通过不代替实际 UI 操作验收。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/SUBTASKS.csv b/.codex-tasks/brand-friendly-template-content-epic/SUBTASKS.csv index f9f265b..19ba242 100644 --- a/.codex-tasks/brand-friendly-template-content-epic/SUBTASKS.csv +++ b/.codex-tasks/brand-friendly-template-content-epic/SUBTASKS.csv @@ -1,6 +1,6 @@ id,task,task_type,status,depends_on,task_dir,acceptance_criteria,validation_command,completed_at,retry_count,notes -1,模板与 Admin 内容契约,single-full,TODO,,tasks/template-admin-contract,manifest 声明数据槽位资产槽位字段语义和通俗编辑文案,pnpm --filter @personal-brand/template-contract typecheck,,0,不引入模板专属后端 if else -2,RuntimeWorkspace 完整投影,single-full,TODO,1,tasks/runtime-workspace-projection,导航和 offering presentation/assets 完整且品牌隔离,pnpm --filter @personal-brand/api test:integration,,0,不得丢弃模板声明字段 -3,发布模板适配校验,single-full,TODO,1;2,tasks/publication-compatibility,发布前给出可行动缺失提示并写入快照,pnpm --filter @personal-brand/api test:integration,,0,覆盖缺图缺字段缺表单场景 -4,品牌友好内容工作台,single-full,TODO,1;2;3,tasks/brand-content-workbench,普通品牌管理员可按业务语言配置并发布,pnpm --filter @personal-brand/admin build,,0,不暴露 JSON schema renderer capability -5,双模板回归与验收,single-full,TODO,1;2;3;4,tasks/template-e2e-regression,阿成和林境品牌数据与模板产物均正确,pnpm test:template-compiler,,0,包含发布快照和品牌隔离回归 +1,模板与 Admin 内容契约,single-full,DONE,,tasks/template-admin-contract,manifest 声明数据槽位资产槽位字段语义和通俗编辑文案,pnpm --filter @personal-brand/template-contract typecheck,2026-09-25,0,不引入模板专属后端 if else +2,RuntimeWorkspace 完整投影,single-full,DONE,1,tasks/runtime-workspace-projection,导航和 offering presentation/assets 完整且品牌隔离,pnpm --filter @personal-brand/api test:integration,2026-09-25,0,37 项通过 +3,发布模板适配校验,single-full,DONE,1;2,tasks/publication-compatibility,发布前给出可行动缺失提示并写入快照,pnpm --filter @personal-brand/api test:integration,2026-09-25,0,缺失内容拦截及修复流程通过 +4,品牌友好内容工作台,single-full,DONE,1;2;3,tasks/brand-content-workbench,普通品牌管理员可按业务语言配置并发布,pnpm --filter @personal-brand/admin build,2026-09-25,0,声明驱动编辑;仅写 brand.config binding;Admin 单测和 API 集成通过 +5,双模板回归与验收,single-full,DONE,1;2;3;4,tasks/template-e2e-regression,阿成和林境品牌数据与模板产物均正确,pnpm test:template-compiler,2026-09-25,0,包含 Admin 声明品牌隔离、public 隔离、原生 tabbar 和发布契约回归 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/PROGRESS.md new file mode 100644 index 0000000..960f2ec --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/PROGRESS.md @@ -0,0 +1,27 @@ +# 进度 + +- 任务:品牌友好内容工作台 +- 形态:single-full +- 进度:4/4 +- 当前:完成,进入双模板回归。 +- 真相文件:`TODO.csv` + +## 结果 + +- `GET /admin/workspace` 按当前会话品牌的 `visualTemplateKey` 返回模板 `displayName`、通俗编辑分组和图片槽位。 +- Admin 页面根据模板声明渲染不同分组、说明、字段、输入类型、必填和图片预览,不再硬编码模板页面字段。 +- 编辑器只处理 `brand.config.*` binding;按声明合并回已有品牌 config,保留其它顶层与嵌套内容,拒绝原型链路径。 +- 保存成功后刷新品牌、workspace、小程序 Runtime 和发布检查;请求失败时保留表单值并显示错误。 +- public Runtime 不暴露 Admin 编辑声明。 + +## 验证 + +- `pnpm --filter @personal-brand/api typecheck` +- `pnpm --filter @personal-brand/admin test`,断言脚本通过,覆盖配置保留、嵌套 binding 和越界路径拒绝。 +- `pnpm --filter @personal-brand/admin build` +- `pnpm validate:templates` +- `pnpm --filter @personal-brand/api test:integration`,37 项通过。 + +## 偏差与修正 + +- 集成测试首次发现模板源文件和生成目录不同步,Admin 因此读不到新增的主图编辑项。运行 `pnpm generate:template-catalog` 后重跑验证通过;模板目录指纹校验会阻止以后带着过期生成目录交付。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/SPEC.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/SPEC.md new file mode 100644 index 0000000..9ce4e64 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/SPEC.md @@ -0,0 +1,14 @@ +# 品牌友好内容工作台 + +## 目标 + +Admin 品牌表达编辑区按当前视觉模板的 `admin.sections` 和资产槽位显示字段。字段标题、帮助和输入类型全部来自模板声明,普通品牌管理员不接触内部 binding 或模板技术配置。 + +## 完成标准 + +- Admin workspace 返回当前品牌模板的编辑声明,按会话品牌隔离。 +- 品牌编辑页不再硬编码首页、案例、咨询等公共字段集合。 +- text、textarea、phone、image、number 均按声明渲染。 +- 保存只更新声明对应的品牌配置路径,保留其他品牌配置。 +- 保存失败保留用户输入,并提供可读错误;发布检查可跳转到对应编辑页。 +- Admin production build 与 API 授权集成测试通过。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/TODO.csv b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/TODO.csv new file mode 100644 index 0000000..edd0bb7 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/brand-content-workbench/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,在 Admin workspace 提供品牌编辑声明,DONE,响应包含当前视觉模板的 sections 与 asset slots,pnpm --filter @personal-brand/api test:integration,2026-09-25,1,同步生成模板目录后通过;集成测试断言编辑声明 +2,声明驱动渲染品牌内容表单,DONE,阿成和林境显示不同业务文案与字段,pnpm --filter @personal-brand/admin build,2026-09-25,0,字段类型和业务文案完全来自当前模板声明 +3,按 binding 保存配置并保留输入,DONE,局部保存不会覆盖未编辑品牌配置,pnpm --filter @personal-brand/admin test,2026-09-25,0,覆盖嵌套更新、配置保留与越界 binding 拒绝 +4,验证权限品牌隔离和构建,DONE,Admin API 和生产构建通过,pnpm --filter @personal-brand/api test:integration,2026-09-25,1,37 项集成测试通过;缺少登录为 401、客户角色为 403 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/PROGRESS.md new file mode 100644 index 0000000..d0b0cae --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/PROGRESS.md @@ -0,0 +1,22 @@ +# 进度 + +- 任务:发布模板适配校验 +- 形态:single-full +- 进度:4/4 +- 当前:已完成,Epic 转入品牌友好内容工作台。 +- 真相文件:`TODO.csv` + +## 结果 + +- 发布检查读取视觉模板 package 的必填字段和媒体槽位。 +- 缺少主理人信息、品牌主图、任一业务封面、咨询表单时阻止发布。 +- 每项缺失提示返回编辑入口与模板编写的操作说明,用户界面不展示 binding。 +- API 集成测试覆盖缺内容拦截、修复后发布、授权与品牌隔离。 + +## 验证 + +- `pnpm --filter @personal-brand/api typecheck` +- `pnpm validate:templates` +- `pnpm --filter @personal-brand/api test:integration`,37 项通过。 +- `pnpm --filter @personal-brand/admin build` +- `pnpm format:check` diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/SPEC.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/SPEC.md new file mode 100644 index 0000000..7fa684f --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/SPEC.md @@ -0,0 +1,13 @@ +# 发布模板适配校验 + +## 目标 + +发布前根据当前品牌安装的视觉模板声明检查必需内容、媒体和咨询配置,返回品牌管理员能直接处理的中文提示。 + +## 完成标准 + +- 校验读取 package manifest,不按 template key 分支。 +- 缺少图片、品牌介绍、业务提供项或可用咨询表单时禁止发布。 +- readiness 返回用户可读项目名和补充位置提示,不返回内部 binding 或 manifest key。 +- 发布快照同时记录被校验的模板 package manifest。 +- API 集成测试覆盖通过与失败场景、权限和品牌隔离。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/TODO.csv b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/TODO.csv new file mode 100644 index 0000000..a40c989 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/publication-compatibility/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,将图片槽位映射到业务字段,DONE,图片要求含内部绑定和用户可读建议,pnpm validate:templates,2026-09-25,0,通过 +2,实现声明驱动的发布检查,DONE,必填内容按 manifest 校验并返回通俗提示,pnpm --filter @personal-brand/api typecheck,2026-09-25,0,通过 +3,补足发布 readiness 测试,DONE,覆盖缺图缺主理人缺表单和成功发布,pnpm --filter @personal-brand/api test:integration,2026-09-25,0,37 项通过 +4,更新任务与文档,DONE,契约和校验语义有记录且验证通过,pnpm format:check,2026-09-25,0,通过 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/PROGRESS.md new file mode 100644 index 0000000..400590a --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/PROGRESS.md @@ -0,0 +1,24 @@ +# 进度 + +- 任务:RuntimeWorkspace 完整投影 +- 形态:single-full +- 进度:4/4 +- 当前:已完成,进入发布模板适配校验。 +- 真相文件:`TODO.csv` + +## 结果 + +- 发布快照保存视觉模板 package manifest;Runtime 导航从快照投影,不再固定为三项。 +- 阿成输出 5 项导航,林境输出 3 项导航;公开 Runtime 不返回 Admin binding 清单。 +- offering 业务展示配置投影为 `presentation` 扩展字段,小程序 view model 原样保留。 +- 生成目录由 package `template.json` 产生,并以 SHA-256 指纹阻止目录过期。 + +## 验证 + +- `pnpm --filter @personal-brand/api typecheck` +- `pnpm validate:templates` +- `pnpm test:template-compiler` +- `pnpm validate:template-release` +- `node --test apps/miniapp/test/runtime-workspace.test.cjs` +- `pnpm --filter @personal-brand/api test` +- `pnpm --filter @personal-brand/api test:integration`,37 项通过。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/SPEC.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/SPEC.md new file mode 100644 index 0000000..c580857 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/SPEC.md @@ -0,0 +1,18 @@ +# RuntimeWorkspace 完整投影 + +## 目标 + +让已发布模板声明的数据槽位、媒体槽位、导航和业务提供项展示属性完整进入 `RuntimeWorkspace`,并保持品牌隔离。控制器只做投影,不能按模板 key 写分支。 + +## 完成标准 + +- 已发布快照中的模板内容契约可被 RuntimeWorkspace 消费。 +- 导航来自发布模板声明,阿成保留 5 项、林境保留 3 项。 +- offering 的 `presentation` 扩展属性不被控制器丢弃。 +- 增加集成测试覆盖两个品牌和未发布品牌隔离。 + +## 当前事实 + +- `PublicWorkspaceController` 当前固定返回 3 项导航。 +- `runtimeOfferings` 当前只投影少量 `presentation` 字段。 +- 发布快照已保存 visual manifest,尚未保存 package content contract。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/TODO.csv b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/TODO.csv new file mode 100644 index 0000000..f6c0a52 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/runtime-workspace-projection/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,审计快照与 Runtime 类型,DONE,明确契约快照和 RuntimeWorkspace 的最小变化,rg -n "BrandReleaseSnapshot|RuntimeWorkspace|navigation" apps/api packages/types,2026-09-25,0,已确认快照需要 package contract,导航固定三项且 presentation 丢字段 +2,投影发布模板声明和导航,DONE,RuntimeWorkspace 返回快照模板契约及声明导航,pnpm --filter @personal-brand/api typecheck,2026-09-25,0,通过 +3,保留 offering 展示属性,DONE,presentation 扩展字段在 API 与小程序 view model 中保留,node --test apps/miniapp/test/runtime-workspace.test.cjs,2026-09-25,0,通过 +4,补充双品牌隔离测试,DONE,阿成林境导航和品牌数据隔离测试通过,pnpm --filter @personal-brand/api test:integration,2026-09-25,0,37 项通过 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/PROGRESS.md new file mode 100644 index 0000000..dfbc798 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/PROGRESS.md @@ -0,0 +1,21 @@ +# 进度 + +- 任务:模板与 Admin 内容契约 +- 形态:single-full +- 进度:4/4 +- 当前:#1 已完成,Epic 转入 RuntimeWorkspace 完整投影。 +- 真相文件:`TODO.csv` + +## 发现 + +- 当前 `PresentationEditor` 硬编码了一组跨模板字段,不能表达阿成的出摊信息和林境的项目案例语义。 +- 当前 package manifest 只覆盖构建、导航和 renderer,不能驱动发布检查或用户可见编辑界面。 +- `packages/config` 仍保留运行时 visual manifest;后续任务将把 package 内容契约投影进发布快照,避免按模板 key 分支。 + +## 验证 + +- `pnpm --filter @personal-brand/template-contract typecheck` +- `pnpm validate:templates` +- `pnpm test:template-compiler` +- `pnpm validate:template-release` +- `pnpm format:check` diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/SPEC.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/SPEC.md new file mode 100644 index 0000000..6babf56 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/SPEC.md @@ -0,0 +1,16 @@ +# 模板与 Admin 内容契约 + +## 目标 + +由每个视觉模板 package 声明自身需要的业务内容、媒体和品牌管理员编辑分组。平台只读取、校验与投影声明;不以模板 key 分支,不向品牌用户暴露 renderer、schema 或 JSON。 + +## 完成标准 + +- 两个现有模板都声明 data slots、asset slots 和通俗编辑区块。 +- 合约类型和校验能拒绝不完整的模板声明。 +- 记录模板 package 为编辑说明唯一来源的架构决策。 + +## 非目标 + +- 本任务不改动 RuntimeWorkspace 投影、数据库或 Admin 页面。 +- 不实现新的小程序模板。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/TODO.csv b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/TODO.csv new file mode 100644 index 0000000..32a3ff4 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-admin-contract/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,审计现有模板与编辑字段,DONE,两模板的页面数据和当前 Admin 字段已归纳,rg -n "visualPresentation|presentation" packages/template-*,,0,完成于本轮 +2,定义并实现模板内容契约,DONE,合约包含数据槽位媒体槽位和通俗编辑区块,pnpm --filter @personal-brand/template-contract typecheck,2026-09-25,0,通过 +3,为阿成与林境声明编辑契约,DONE,两个 template.json 通过契约和发布校验,pnpm validate:templates,2026-09-25,0,通过 +4,记录 ADR 并验证,DONE,ADR 说明来源边界和迁移路径,pnpm format:check,2026-09-25,0,通过 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/PROGRESS.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/PROGRESS.md new file mode 100644 index 0000000..ea994a4 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/PROGRESS.md @@ -0,0 +1,17 @@ +# 进度 + +- 任务:双模板端到端回归 +- 形态:single-full +- 进度:4/4 +- 当前:自动化回归通过;Epic 待最终全量验证和进度关闭。 +- 真相文件:`TODO.csv` + +## 验证 + +- `pnpm --filter @personal-brand/api test:integration`,37 项通过;新增阿成/林境 Admin 声明品牌隔离断言、错误角色拒绝和 public manifest 隔离断言。 +- `node --test apps/miniapp/test/runtime-workspace.test.cjs` +- `pnpm test:template-compiler`,两套真实产物通过:阿成 5 项原生 tabbar,林境 3 项原生 tabbar,入口、renderer 和页面清理均符合声明。 +- `pnpm validate:templates` +- `pnpm validate:template-release` +- `pnpm --filter @personal-brand/admin test` +- `pnpm --filter @personal-brand/admin build` diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/SPEC.md b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/SPEC.md new file mode 100644 index 0000000..e211076 --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/SPEC.md @@ -0,0 +1,13 @@ +# 双模板端到端回归 + +## 目标 + +验证阿成校园餐与林境建筑画册作为独立视觉模板时,模板声明、Admin 编辑项、品牌数据隔离、Runtime 投影、发布快照和小程序构建均保持一致。 + +## 完成标准 + +- Admin workspace 根据当前品牌返回对应模板编辑清单,品牌切换不会串用另一模板声明。 +- 受保护 workspace 路由覆盖未登录、错误角色和授权成功路径。 +- public Runtime 不暴露 Admin 内部编辑声明;品牌内容由正确品牌快照投影。 +- 两个模板产物使用微信原生 tabbar,导航项数、entrypoint 和 renderer 与 package manifest 相符。 +- 模板 package 目录、生成目录与发布锁定版本校验通过。 diff --git a/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/TODO.csv b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/TODO.csv new file mode 100644 index 0000000..7f8c3ba --- /dev/null +++ b/.codex-tasks/brand-friendly-template-content-epic/tasks/template-e2e-regression/TODO.csv @@ -0,0 +1,5 @@ +id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes +1,回归 Admin 声明与多品牌隔离,DONE,阿成与林境会话分别返回匹配模板声明且角色校验生效,pnpm --filter @personal-brand/api test:integration,2026-09-25,0,37 项集成测试通过并新增声明隔离断言 +2,回归 Runtime 数据投影与发布边界,DONE,品牌展示字段保留且 public 不含 Admin manifest,node --test apps/miniapp/test/runtime-workspace.test.cjs,2026-09-25,0,Runtime fixture 覆盖 offering 展示扩展字段 +3,回归两个小程序模板构建产物,DONE,两模板 entrypoint 原生 tabbar renderer 和页面裁剪均符合 manifest,pnpm test:template-compiler,2026-09-25,0,Acheng 5 tab 与 Linjing 3 tab 编译测试通过 +4,校验模板目录与版本发布契约,DONE,目录指纹、manifest 与发布版本锁定一致,pnpm validate:templates && pnpm validate:template-release,2026-09-25,0,模板包与生成目录同步 diff --git a/apps/admin/package.json b/apps/admin/package.json index fb25b7c..7241437 100644 --- a/apps/admin/package.json +++ b/apps/admin/package.json @@ -13,6 +13,7 @@ "scripts": { "build": "pnpm --filter @personal-brand/api-client build && vite build", "dev": "pnpm --filter @personal-brand/api-client build && vite", + "test": "node --experimental-strip-types --test test/*.test.mjs", "lint": "eslint .", "typecheck": "tsc -p tsconfig.json --noEmit", "clean": "rimraf dist" diff --git a/apps/admin/src/features/brand/BrandPage.tsx b/apps/admin/src/features/brand/BrandPage.tsx index 2cdd60a..c27cd4b 100644 --- a/apps/admin/src/features/brand/BrandPage.tsx +++ b/apps/admin/src/features/brand/BrandPage.tsx @@ -7,24 +7,20 @@ import { ImageUrlField } from "../../components/ImageUrlField.js"; import { MutationError, QueryState } from "../../components/QueryState.js"; import { PresentationEditor } from "./PresentationEditor.js"; -function textValue(value: unknown): string { - return typeof value === "string" ? value : ""; -} - export function BrandPage() { const client = createApiClient(); const queryClient = useQueryClient(); const [form] = Form.useForm(); const brand = useQuery({ queryKey: ["admin-brand"], queryFn: () => client.getAdminBrand() }); + const workspace = useQuery({ + queryKey: ["admin-workspace"], + queryFn: () => client.getAdminWorkspace(), + }); const template = useQuery({ queryKey: ["template", brand.data?.templateKey], queryFn: () => client.getPublicTemplate(brand.data!.templateKey), enabled: Boolean(brand.data?.templateKey), }); - const runtime = useQuery({ - queryKey: ["public-runtime-workspace"], - queryFn: () => client.getPublicWorkspace(), - }); const save = useMutation({ mutationFn: (values: Partial) => client.updateAdminBrand(values), onSuccess: () => { @@ -148,43 +144,10 @@ export function BrandPage() { ; - offerings?: Record; - detail?: Record; - profile?: Record; - inquiry?: Record; - success?: Record; - records?: Record; - }) ?? {}), - }} - runtimeValue={ - runtime.data?.brand - ? { - identity: { - founder: textValue(runtime.data.brand.config?.founder), - title: textValue(runtime.data.brand.config?.title), - slogan: textValue(runtime.data.brand.config?.slogan), - }, - ...((runtime.data.brand.config?.visualPresentation as { - home?: Record; - inquiry?: Record; - profile?: Record; - }) ?? {}), - } - : undefined - } - runtimeLoading={runtime.isLoading} - runtimeError={runtime.error} + templateContent={workspace.data?.templateContent} + config={brand.data.config} + loading={workspace.isLoading} + error={workspace.error} /> diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx index 9b82b73..b71caf9 100644 --- a/apps/admin/src/features/brand/PresentationEditor.tsx +++ b/apps/admin/src/features/brand/PresentationEditor.tsx @@ -1,189 +1,155 @@ -import { Alert, Button, Card, Col, Form, Input, Row, Space, Typography, message } from "antd"; +import { + Alert, + Button, + Card, + Col, + Form, + Input, + InputNumber, + Row, + Space, + Typography, + message, +} from "antd"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { useEffect } from "react"; +import { useEffect, useMemo } from "react"; +import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client"; import { createApiClient } from "../../lib/api.js"; +import { ImageUrlField } from "../../components/ImageUrlField.js"; import { MutationError } from "../../components/QueryState.js"; +import { + applyPresentationValues, + presentationFieldName, + readPresentationValue, + type PresentationValues, +} from "./presentation-bindings.js"; interface PresentationEditorProps { - initialValue: PresentationFormValues; - runtimeValue?: PresentationFormValues | undefined; - runtimeLoading?: boolean | undefined; - runtimeError?: unknown; + templateContent: AdminTemplateContent | null | undefined; + config: Record | null | undefined; + loading?: boolean; + error?: unknown; } -type PresentationFormValues = { - identity?: Record; - home?: Record; - offerings?: Record; - detail?: Record; - profile?: Record; - inquiry?: Record; - success?: Record; - records?: Record; -}; +function renderField(field: TemplateAdminField) { + if (field.input === "textarea") + return ( + + ); + if (field.input === "image") + return ; + if (field.input === "number") + return ; + return ( + + ); +} export function PresentationEditor({ - initialValue, - runtimeValue, - runtimeLoading, - runtimeError, + templateContent, + config, + loading, + error, }: PresentationEditorProps) { - const [form] = Form.useForm(); + const [form] = Form.useForm(); const queryClient = useQueryClient(); + const sections = templateContent?.admin.sections ?? []; + const initialValues = useMemo(() => { + const values: PresentationValues = {}; + for (const section of sections) { + for (const field of section.fields) { + values[presentationFieldName(section.key, field.key)] = readPresentationValue( + config, + field.binding, + ); + } + } + return values; + }, [config, sections]); + const save = useMutation({ - mutationFn: (values: PresentationFormValues) => - createApiClient().updateAdminBrandPresentation(values), + mutationFn: (values: PresentationValues) => { + const nextConfig = applyPresentationValues(config, sections, values); + return createApiClient().updateAdminBrand({ config: nextConfig }); + }, onSuccess: () => { - message.success("页面表达已保存,小程序将使用最新内容"); + message.success("页面内容已保存,小程序将使用最新内容"); void queryClient.invalidateQueries({ queryKey: ["admin-brand"] }); + void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }); void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] }); + void queryClient.invalidateQueries({ queryKey: ["publication-readiness"] }); }, }); + useEffect(() => { - form.setFieldsValue(initialValue); - }, [form, initialValue]); + form.setFieldsValue(initialValues); + }, [form, initialValues]); return ( - 普通用户配置} - > + - 这里的内容会显示在小程序中。只填写你希望访客看到的话,不需要理解模板或技术配置。 + 编辑访客在小程序中看到的文字和图片。不同模板会提供适合本行业的内容项目。 - {runtimeLoading ? : null} - {runtimeError ? ( - - ) : runtimeValue ? ( - - - {runtimeValue.identity?.founder || "尚未设置主理人 / 老板姓名"} - - {runtimeValue.identity?.title ? ( - · {runtimeValue.identity.title} - ) : null} - - {runtimeValue.home?.proofTitle || "尚未设置信任介绍标题"} - - - {runtimeValue.inquiry?.subtitle || "尚未设置咨询说明"} - - - 咨询按钮:{runtimeValue.inquiry?.submitLabel || "未设置"} · 记录入口: - {runtimeValue.profile?.recordsTitle || "未设置"} - - + {loading ? : null} + {error ? ( + + ) : null} + {!loading && !error && !templateContent ? ( + + ) : null} + {templateContent ? ( + <> + {templateContent.displayName} +
save.mutate(values)} + > + {sections.map((section) => ( + + {section.description} + + {section.fields.map((field) => ( + + + {renderField(field)} + + + ))} + + + ))} + + + + +
+ ) : null} -
save.mutate(values)} - > - - - 访客需要先知道是谁在提供服务。这里填写主理人或老板的公开信息。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
); } diff --git a/apps/admin/src/features/brand/presentation-bindings.ts b/apps/admin/src/features/brand/presentation-bindings.ts new file mode 100644 index 0000000..f3560d9 --- /dev/null +++ b/apps/admin/src/features/brand/presentation-bindings.ts @@ -0,0 +1,74 @@ +export type PresentationField = { + key: string; + binding: string; +}; + +export type PresentationSection = { + key: string; + fields: PresentationField[]; +}; + +export type PresentationValues = Record; + +function asObject(value: unknown): Record { + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; +} + +function safePath(binding: string): string[] | null { + if (!binding.startsWith("brand.config.")) return null; + const path = binding.slice("brand.config.".length).split("."); + if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part))) + return null; + return path; +} + +export function presentationFieldName(sectionKey: string, fieldKey: string): string { + return `${sectionKey}:${fieldKey}`; +} + +export function readPresentationValue( + config: Record | null | undefined, + binding: string, +): string | number | undefined { + const path = safePath(binding); + if (!path) return undefined; + let value: unknown = asObject(config); + for (const part of path) value = asObject(value)[part]; + return typeof value === "string" || typeof value === "number" ? value : undefined; +} + +function writePath( + source: Record, + path: string[], + value: string | number | null | undefined, +): Record { + const [head, ...tail] = path; + if (!head) return source; + if (!tail.length) return { ...source, [head]: value ?? "" }; + return { + ...source, + [head]: writePath(asObject(source[head]), tail, value), + }; +} + +export function applyPresentationValues( + config: Record | null | undefined, + sections: PresentationSection[], + values: PresentationValues, +): Record { + let nextConfig = { ...asObject(config) }; + for (const section of sections) { + for (const field of section.fields) { + const path = safePath(field.binding); + if (!path) continue; + nextConfig = writePath( + nextConfig, + path, + values[presentationFieldName(section.key, field.key)], + ); + } + } + return nextConfig; +} diff --git a/apps/admin/src/features/publication/PublicationPage.tsx b/apps/admin/src/features/publication/PublicationPage.tsx index 32900bc..de37025 100644 --- a/apps/admin/src/features/publication/PublicationPage.tsx +++ b/apps/admin/src/features/publication/PublicationPage.tsx @@ -281,10 +281,15 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool {check.passed ? "已完成" : "待完善"} {check.label} + {check.help ? ( + {check.help} + ) : null} {!check.passed && ( diff --git a/apps/admin/test/presentation-bindings.test.mjs b/apps/admin/test/presentation-bindings.test.mjs new file mode 100644 index 0000000..1ae1cab --- /dev/null +++ b/apps/admin/test/presentation-bindings.test.mjs @@ -0,0 +1,58 @@ +import assert from "node:assert/strict"; +import { + applyPresentationValues, + presentationFieldName, + readPresentationValue, +} from "../src/features/brand/presentation-bindings.ts"; + +const config = { + founder: "阿成", + visualPresentation: { + home: { worksTitle: "原标题", preserveMe: "保留" }, + inquiry: { subtitle: "原说明" }, + }, + unrelatedSetting: true, +}; +const sections = [ + { + key: "home", + fields: [ + { key: "founder", binding: "brand.config.founder" }, + { key: "worksTitle", binding: "brand.config.visualPresentation.home.worksTitle" }, + ], + }, +]; +const next = applyPresentationValues(config, sections, { + [presentationFieldName("home", "founder")]: "阿成主理人", + [presentationFieldName("home", "worksTitle")]: "今日套餐", +}); + +assert.equal(readPresentationValue(next, "brand.config.founder"), "阿成主理人"); +assert.equal( + readPresentationValue(next, "brand.config.visualPresentation.home.worksTitle"), + "今日套餐", +); +assert.equal(next.visualPresentation.home.preserveMe, "保留"); +assert.equal(next.visualPresentation.inquiry.subtitle, "原说明"); +assert.equal(next.unrelatedSetting, true); +assert.equal(config.founder, "阿成"); + +const unsafe = applyPresentationValues( + { founder: "原主理人" }, + [ + { + key: "unsafe", + fields: [ + { key: "tenant", binding: "brand.id" }, + { key: "prototype", binding: "brand.config.__proto__.polluted" }, + ], + }, + ], + { + [presentationFieldName("unsafe", "tenant")]: "other-brand", + [presentationFieldName("unsafe", "prototype")]: "yes", + }, +); + +assert.deepEqual(unsafe, { founder: "原主理人" }); +assert.equal({}.polluted, undefined); diff --git a/apps/api/src/admin-workspace.controller.ts b/apps/api/src/admin-workspace.controller.ts index 802a117..fa9e00f 100644 --- a/apps/api/src/admin-workspace.controller.ts +++ b/apps/api/src/admin-workspace.controller.ts @@ -31,6 +31,8 @@ import { capabilityPlugins, getBrandTemplate, getTemplateSampleContent, + getTemplatePackageManifestForVisualKey, + getDefaultVisualTemplateKey, resolveCapabilities, } from "@personal-brand/config"; import { TemplateWorkspaceService } from "./template-workspace.service.js"; @@ -167,7 +169,32 @@ class AdminWorkspaceController { this.prisma.offering.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }), this.prisma.inquiryForm.findMany({ where: { brandId }, orderBy: { updatedAt: "desc" } }), ]); - return { brand, installations, modules, fields, offerings, forms }; + const config = this.jsonObject(brand?.config); + const templateKey = + typeof config.visualTemplateKey === "string" + ? config.visualTemplateKey + : getDefaultVisualTemplateKey(brand?.templateKey ?? "personal"); + const manifest = getTemplatePackageManifestForVisualKey(templateKey); + return { + brand, + installations, + modules, + fields, + offerings, + forms, + templateContent: manifest + ? { + displayName: manifest.displayName, + admin: manifest.admin, + assetSlots: manifest.assetSlots, + } + : null, + }; + } + private jsonObject(value: unknown): Record { + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; } @Post("install") async install( diff --git a/apps/api/src/brand-release-api.service.ts b/apps/api/src/brand-release-api.service.ts index 081d292..b42037f 100644 --- a/apps/api/src/brand-release-api.service.ts +++ b/apps/api/src/brand-release-api.service.ts @@ -10,6 +10,7 @@ import { getVisualTemplate, isVisualTemplateCompatible, getDefaultVisualTemplateKey, + getTemplatePackageManifestForVisualKey, } from "@personal-brand/config"; import { PrismaService } from "./prisma.service.js"; import { BrandReleaseService } from "./brand-release.service.js"; @@ -44,7 +45,13 @@ export class BrandReleaseApiService { database: Prisma.TransactionClient = this.prisma, ): Promise<{ ready: boolean; - checks: Array<{ key: string; label: string; passed: boolean }>; + checks: Array<{ + key: string; + label: string; + passed: boolean; + help?: string; + destination?: string; + }>; }> { const brand = await database.brandProfile.findUnique({ where: { id: brandId }, @@ -61,8 +68,12 @@ export class BrandReleaseApiService { ? config.visualTemplateKey : getDefaultVisualTemplateKey(brand?.templateKey ?? "personal"); const visual = getVisualTemplate(visualKey); + const packageManifest = getTemplatePackageManifestForVisualKey(visualKey); const [offerings, forms, trust] = await Promise.all([ - database.offering.findMany({ where: { brandId, isEnabled: true }, select: { id: true } }), + database.offering.findMany({ + where: { brandId, isEnabled: true }, + select: { id: true, name: true, coverUrl: true, config: true }, + }), database.inquiryForm.findMany({ where: { brandId, isEnabled: true }, select: { offeringId: true, fieldsSnapshot: true }, @@ -77,26 +88,115 @@ export class BrandReleaseApiService { form.fieldsSnapshot.length > 0 && validateFieldSnapshot(form.fieldsSnapshot).length === 0, ); - const checks = [ - { key: "brand", label: "请先完善品牌名称", passed: Boolean(brand?.name.trim()) }, + const checks: Array<{ + key: string; + label: string; + passed: boolean; + help?: string; + destination?: string; + }> = [ + { + key: "brand", + label: "请先完善品牌名称", + passed: Boolean(brand?.name.trim()), + destination: "/admin/brand", + }, { key: "positioning", label: "请先完善品牌定位和介绍", passed: Boolean(brand?.tagline?.trim() && brand.description?.trim()), + destination: "/admin/brand", }, { key: "template", label: "当前行业模板不存在", passed: Boolean(template) }, { key: "visual", label: "当前视觉模板不适配行业模板", passed: Boolean(visual && template && isVisualTemplateCompatible(visual, template.key)), + destination: "/admin/publication", + }, + { + key: "offerings", + label: "至少需要一项已启用的业务提供项", + passed: offerings.length > 0, + destination: "/admin/services", + }, + { + key: "forms", + label: "至少需要一个可用的咨询表单", + passed: usableForms.length > 0, + destination: "/admin/workspace", + }, + { + key: "trust", + label: "至少需要一条已发布的信任内容", + passed: trust > 0, + destination: "/admin/trust", }, - { key: "offerings", label: "至少需要一项已启用的业务提供项", passed: offerings.length > 0 }, - { key: "forms", label: "至少需要一个可用的咨询表单", passed: usableForms.length > 0 }, - { key: "trust", label: "至少需要一条已发布的信任内容", passed: trust > 0 }, ]; + const brandRecord = { ...this.jsonObject(brand), config }; + for (const section of packageManifest?.admin.sections ?? []) { + for (const field of section.fields) { + if (field.required !== true) continue; + const present = this.resolveBinding(field.binding, { + brand: brandRecord, + offerings, + }); + checks.push({ + key: `content:${section.key}:${field.key}`, + label: present + ? `${section.title}:${field.label}` + : `请补充「${section.title}」中的「${field.label}」`, + passed: present, + help: section.description, + destination: + section.target === "offering" + ? "/admin/services" + : section.target === "trust" + ? "/admin/trust" + : section.target === "inquiry" + ? "/admin/workspace" + : "/admin/brand", + }); + } + } + for (const slot of packageManifest?.assetSlots ?? []) { + if (slot.required !== true) continue; + const present = + slot.target === "offering" + ? offerings.length > 0 && offerings.every((item) => Boolean(item.coverUrl?.trim())) + : slot.target === "brand" + ? this.resolveBinding(slot.binding, { brand: brandRecord, offerings }) + : trust > 0; + checks.push({ + key: `asset:${String(slot.key)}`, + label: present ? `已添加${String(slot.label)}` : `请添加${String(slot.label)}`, + passed: present, + help: String(slot.help), + destination: slot.target === "offering" ? "/admin/services" : "/admin/brand", + }); + } return { ready: checks.every((check) => check.passed), checks }; } + private resolveBinding( + binding: string, + context: { + brand: Record; + offerings: Array<{ id: string; name: string; coverUrl: string | null; config: unknown }>; + }, + ): boolean { + const segments = binding.split("."); + let value: unknown; + if (segments[0] === "brand") value = context.brand; + else if (segments[0] === "offering") value = context.offerings[0]; + else return false; + for (const segment of segments.slice(1)) { + if (!value || typeof value !== "object" || Array.isArray(value)) return false; + value = (value as Record)[segment]; + } + return typeof value === "string" ? value.trim().length > 0 : Boolean(value); + } + async publish(brandId: string, actorId: string, note?: string): Promise { return this.withVersionRetry(() => this.prisma.$transaction( diff --git a/apps/api/src/brand-release.service.ts b/apps/api/src/brand-release.service.ts index 6034b06..81fd963 100644 --- a/apps/api/src/brand-release.service.ts +++ b/apps/api/src/brand-release.service.ts @@ -5,6 +5,7 @@ import { getVisualTemplate, getVisualTemplateManifest, getDefaultVisualTemplateKey, + getTemplatePackageManifestForVisualKey, } from "@personal-brand/config"; import { PrismaService } from "./prisma.service.js"; @@ -15,6 +16,7 @@ export interface BrandReleaseSnapshot { templateDefinition?: ReturnType | null; visualTemplateDefinition?: ReturnType | null; visualTemplateManifest?: ReturnType | null; + templatePackageManifest?: ReturnType | null; brand: Record | null; installation: Record | null; modules: unknown[]; @@ -61,6 +63,7 @@ export async function buildBrandReleaseSnapshot( templateDefinition: getBrandTemplate(templateKey) ?? null, visualTemplateDefinition: getVisualTemplate(visualKey) ?? null, visualTemplateManifest: getVisualTemplateManifest(visualKey) ?? null, + templatePackageManifest: getTemplatePackageManifestForVisualKey(visualKey) ?? null, brand: brand ? jsonObject(brand) : null, installation: installation ? jsonObject(installation) : null, modules: modules.map((item) => jsonObject(item)), diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts index 6e0b700..898115e 100644 --- a/apps/api/src/modules/public/public-workspace.controller.ts +++ b/apps/api/src/modules/public/public-workspace.controller.ts @@ -10,6 +10,7 @@ import { resolveCapabilities, capabilityPlugins, getDefaultVisualTemplateKey, + getTemplatePackageManifestForVisualKey, } from "@personal-brand/config"; import type { RuntimeInquiryField, @@ -120,6 +121,9 @@ export class PublicWorkspaceController { releaseSnapshot.visualTemplateDefinition ?? getVisualTemplate(visualTemplateKey); const visualTemplateManifest = releaseSnapshot.visualTemplateManifest ?? getVisualTemplateManifest(visualTemplateKey); + const templatePackageManifest = + releaseSnapshot.templatePackageManifest ?? + getTemplatePackageManifestForVisualKey(visualTemplateKey); const runtimeBrand = { ...brandData, ...brandConfig, @@ -177,6 +181,20 @@ export class PublicWorkspaceController { schemaKey: typeof config.schemaKey === "string" ? config.schemaKey : "offering.default", schemaVersion: typeof config.schemaVersion === "string" ? config.schemaVersion : "1.0.0", presentation: { + ...Object.fromEntries( + Object.entries(config).filter( + ([key]) => + ![ + "schemaKey", + "schemaVersion", + "details", + "sections", + "media", + "presentation", + ].includes(key), + ), + ), + ...this.jsonObject(config.presentation), categoryKey: typeof config.categoryKey === "string" ? config.categoryKey : "custom", categoryLabel: typeof config.categoryLabel === "string" ? config.categoryLabel : "业务提供项", @@ -266,11 +284,15 @@ export class PublicWorkspaceController { }, brand: runtimeBrand, navigation: { - tabs: [ - { key: "home", label: "首页", page: "pages/index/index" }, - { key: "offerings", label: "案例与体系", page: "pages/services/index" }, - { key: "profile", label: "主理人与我", page: "pages/bookings/index" }, - ], + tabs: + templatePackageManifest?.navigation.map((tab) => ({ + key: tab.key, + label: tab.label, + page: + templatePackageManifest.entrypoints[ + tab.page as keyof typeof templatePackageManifest.entrypoints + ] ?? tab.page, + })) ?? [], }, modules: runtimeModules, offerings: runtimeOfferings, diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index fdbb83b..dea43cb 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -77,6 +77,70 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async }); } const originalBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } }); + const originalConfig = originalBrand.config; + const originalOffering = await prisma.offering.findFirstOrThrow({ where: { brandId } }); + await prisma.brandProfile.update({ + where: { id: brandId }, + data: { + config: { + ...(originalConfig && typeof originalConfig === "object" ? originalConfig : {}), + heroImage: "", + founder: "", + }, + }, + }); + const missingBrandContent = JSON.parse( + ( + await request("/admin/releases/readiness", { + headers: { authorization: `Bearer ${adminToken}` }, + }) + ).body, + ); + assert.equal(missingBrandContent.ready, false); + assert.equal( + missingBrandContent.checks.find((check) => check.key === "asset:brand.stallHero")?.passed, + false, + ); + assert.equal( + missingBrandContent.checks.find((check) => check.key === "content:identity:founder") + ?.destination, + "/admin/brand", + ); + assert.match( + missingBrandContent.checks.find((check) => check.key === "asset:brand.stallHero")?.help, + /真实摊位/, + ); + assert.equal( + ( + await request("/admin/releases/publish", { + method: "POST", + headers: { authorization: `Bearer ${adminToken}` }, + payload: {}, + }) + ).statusCode, + 400, + ); + await prisma.brandProfile.update({ + where: { id: brandId }, + data: { config: originalConfig }, + }); + await prisma.offering.update({ where: { id: originalOffering.id }, data: { coverUrl: null } }); + const missingOfferingImage = JSON.parse( + ( + await request("/admin/releases/readiness", { + headers: { authorization: `Bearer ${adminToken}` }, + }) + ).body, + ); + assert.equal(missingOfferingImage.ready, false); + assert.equal( + missingOfferingImage.checks.find((check) => check.key === "asset:offering.cover")?.passed, + false, + ); + await prisma.offering.update({ + where: { id: originalOffering.id }, + data: { coverUrl: originalOffering.coverUrl }, + }); await prisma.brandProfile.update({ where: { id: brandId }, data: { tagline: "" } }); const incomplete = await request("/admin/releases/readiness", { headers: { authorization: `Bearer ${adminToken}` }, @@ -319,6 +383,8 @@ test("seeded public workspaces keep personal, food, and doors brands isolated", assert.equal(workspace.template.key, item.templateKey); assert.ok(workspace.visualTemplate?.key); assert.ok(workspace.visualTemplateManifest?.pages?.length > 0); + assert.equal(workspace.navigation.tabs.length, item.templateKey === "food" ? 5 : 3); + assert.equal("templatePackageManifest" in workspace, false); assert.equal(workspace.brand.founder, item.founder); assert.ok(workspace.trustContent.length > 0); assert.ok(workspace.trustPresentation); @@ -333,6 +399,10 @@ test("seeded public workspaces keep personal, food, and doors brands isolated", offering.presentation?.categoryLabel === item.categoryLabel, ), ); + if (item.templateKey === "doors") { + assert.ok(workspace.offerings.some((offering) => offering.presentation.series)); + assert.ok(workspace.offerings.some((offering) => offering.presentation.hardware)); + } return workspace; }), ); @@ -683,6 +753,10 @@ test("admin can install a template and public workspace exposes enabled configur const token = JSON.parse(login.body).token; const before = await request("/admin/workspace"); assert.equal(before.statusCode, 401); + const customerAccess = await request("/admin/workspace", { + headers: { authorization: `Bearer ${customerToken}` }, + }); + assert.equal(customerAccess.statusCode, 403); const installed = await request("/admin/workspace/install", { method: "POST", headers: { authorization: `Bearer ${token}` }, @@ -726,6 +800,14 @@ test("admin can install a template and public workspace exposes enabled configur assert.equal(workspace.statusCode, 200); assert.equal(JSON.parse(workspace.body).installations.length, 1); assert.equal(JSON.parse(workspace.body).fields.length, 5); + const templateContent = JSON.parse(workspace.body).templateContent; + assert.equal(templateContent.displayName, "阿成校园餐"); + assert.ok(templateContent.admin.sections.some((section) => section.title === "首页出摊信息")); + assert.ok( + templateContent.admin.sections + .flatMap((section) => section.fields) + .some((field) => field.binding === "brand.config.heroImage"), + ); const publicWorkspace = await request("/public/workspace"); assert.equal(publicWorkspace.statusCode, 200); const workspaceBody = JSON.parse(publicWorkspace.body); @@ -733,6 +815,7 @@ test("admin can install a template and public workspace exposes enabled configur assert.equal(workspaceBody.template.key, "food"); assert.ok(workspaceBody.modules.length > 0); assert.equal(workspaceBody.modules.length, workspaceBody.runtimeModules.length); + assert.equal("templateContent" in workspaceBody, false); assert.equal(workspaceBody.runtimeModules[0].schemaVersion, "1.0"); assert.ok(workspaceBody.inquiryForm); const conflict = await request("/admin/workspace/install", { @@ -1276,22 +1359,35 @@ test("brand switching isolates admin configuration, offerings, and public worksp assert.equal(switched.statusCode, 201); const doorsToken = JSON.parse(switched.body).token; - const [defaultConfig, doorsConfig, defaultOfferings, doorsOfferings, doorsWorkspace] = - await Promise.all([ - request("/admin/config/brand", { - headers: { authorization: `Bearer ${defaultToken}` }, - }), - request("/admin/config/brand", { - headers: { authorization: `Bearer ${doorsToken}` }, - }), - request("/admin/workspace/offerings", { - headers: { authorization: `Bearer ${defaultToken}` }, - }), - request("/admin/workspace/offerings", { - headers: { authorization: `Bearer ${doorsToken}` }, - }), - request("/public/workspace?brandSlug=linjing-doors"), - ]); + const [ + defaultConfig, + doorsConfig, + defaultOfferings, + doorsOfferings, + defaultAdminWorkspace, + doorsAdminWorkspace, + doorsWorkspace, + ] = await Promise.all([ + request("/admin/config/brand", { + headers: { authorization: `Bearer ${defaultToken}` }, + }), + request("/admin/config/brand", { + headers: { authorization: `Bearer ${doorsToken}` }, + }), + request("/admin/workspace/offerings", { + headers: { authorization: `Bearer ${defaultToken}` }, + }), + request("/admin/workspace/offerings", { + headers: { authorization: `Bearer ${doorsToken}` }, + }), + request("/admin/workspace", { + headers: { authorization: `Bearer ${defaultToken}` }, + }), + request("/admin/workspace", { + headers: { authorization: `Bearer ${doorsToken}` }, + }), + request("/public/workspace?brandSlug=linjing-doors"), + ]); assert.equal(defaultConfig.statusCode, 200); assert.equal(doorsConfig.statusCode, 200); assert.equal(JSON.parse(defaultConfig.body).id, brandId); @@ -1305,6 +1401,10 @@ test("brand switching isolates admin configuration, offerings, and public worksp assert.equal(doorsWorkspace.statusCode, 200); assert.equal(JSON.parse(doorsWorkspace.body).brand.id, doorsBrand.id); assert.equal(JSON.parse(doorsWorkspace.body).template.key, "doors"); + assert.equal(defaultAdminWorkspace.statusCode, 200); + assert.equal(doorsAdminWorkspace.statusCode, 200); + assert.equal(JSON.parse(defaultAdminWorkspace.body).templateContent.displayName, "阿成校园餐"); + assert.equal(JSON.parse(doorsAdminWorkspace.body).templateContent.displayName, "林境建筑画册"); }); test("disabled brand membership blocks existing admin token", async () => { diff --git a/apps/miniapp/test/runtime-workspace.test.cjs b/apps/miniapp/test/runtime-workspace.test.cjs index de4c028..24916d0 100644 --- a/apps/miniapp/test/runtime-workspace.test.cjs +++ b/apps/miniapp/test/runtime-workspace.test.cjs @@ -43,3 +43,28 @@ test("已发布 workspace 正常返回", async () => { }); assert.equal(workspace.brand.name, "测试品牌"); }); + +test("模板声明的业务提供项展示字段会保留在小程序 view model", async () => { + const workspace = await loadWithResponse({ + publication: { status: "published" }, + brand: { name: "测试品牌" }, + offerings: [ + { + id: "offering-1", + name: "别墅入户门", + summary: "山庄项目", + coverUrl: "/cover.jpg", + priceText: "按项目报价", + presentation: { + categoryLabel: "入户大门", + series: "万籁系列", + area: "莫干山", + hardware: "隐藏式地轴", + }, + }, + ], + }); + assert.equal(workspace.offerings[0].series, "万籁系列"); + assert.equal(workspace.offerings[0].area, "莫干山"); + assert.equal(workspace.offerings[0].hardware, "隐藏式地轴"); +}); diff --git a/apps/miniapp/utils/runtime-workspace.js b/apps/miniapp/utils/runtime-workspace.js index 4831634..061a782 100644 --- a/apps/miniapp/utils/runtime-workspace.js +++ b/apps/miniapp/utils/runtime-workspace.js @@ -8,6 +8,7 @@ function toOffering(item) { presentation.details && typeof presentation.details === "object" ? presentation.details : {}; return { ...item, + ...presentation, id: item.id, category: presentation.categoryLabel || "业务提供项", name: item.name, diff --git a/docs/adr/0014-template-admin-content-contract.md b/docs/adr/0014-template-admin-content-contract.md new file mode 100644 index 0000000..cb671eb --- /dev/null +++ b/docs/adr/0014-template-admin-content-contract.md @@ -0,0 +1,34 @@ +# 0014 模板声明品牌内容编辑契约 + +## Context + +平台需要支持大量视觉与交互差异明显的小程序模板。品牌管理员需要配置自己的介绍、案例、图片和咨询内容,但不应理解 renderer、JSON、schema 或模板内部实现。当前 Admin 使用一套硬编码的页面表达字段,无法可靠覆盖阿成校园餐与林境建筑画册的不同业务表达。 + +## Decision + +每个视觉模板 package 的 `template.json` 声明: + +- `dataSlots`:运行时和发布检查需要的稳定业务数据集合; +- `assetSlots`:图片和媒体的业务名称、用途、必填性与推荐比例; +- `admin.sections`:品牌管理员看到的编辑分组、字段文案、帮助、输入类型与内部绑定。 + +模板 package 是页面结构、视觉、交互和内容编辑说明的唯一来源。后端负责校验、品牌隔离、快照与稳定数据投影;Admin 读取声明并渲染业务化表单。`binding`、renderer、capability、schema 等技术信息不会展示给品牌管理员。 + +## Alternatives + +- 继续在 Admin 写共享页面表达字段:不能覆盖行业与视觉差异,模板增多后会产生模板 key 分支。 +- 让品牌管理员编辑 JSON:灵活但不可用,且容易破坏发布内容。 +- 用公共视觉积木约束所有模板:会牺牲模板的页面与交互自由度。 + +## Consequences + +- 新模板必须同时交付页面代码、内容契约、媒体要求和业务化编辑文案。 +- RuntimeWorkspace、发布检查和 Admin 需要在后续任务消费同一契约。 +- 包内 manifest 的版本变更将进入发布快照,保证已发布品牌的展示可追溯。 + +## Migration Plan + +1. 为阿成与林境补齐内容契约。 +2. 将契约投影到 RuntimeWorkspace 和发布快照。 +3. 发布前按必填槽位输出可行动提示。 +4. 用声明驱动品牌管理员工作台,移除硬编码的通用页面表达表单。 diff --git a/eslint.config.mjs b/eslint.config.mjs index ca23680..892f7c2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -11,6 +11,7 @@ export default tseslint.config( "**/prisma/**", "apps/api/test/**/*.test.js", "apps/api/test/**/*.cjs", + "apps/admin/test/**/*.test.mjs", "apps/miniapp/pages/**/*.js", "apps/miniapp/app.js", "apps/admin/vite.config.ts", diff --git a/package.json b/package.json index 5cb2e6e..801dca2 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "db:migrate": "pnpm --filter @personal-brand/api db:migrate", "db:seed": "pnpm --filter @personal-brand/api db:seed", "test:api-client": "pnpm --filter @personal-brand/api exec tsx --test ../../packages/api-client/test/**/*.test.ts", - "validate:templates": "node scripts/validate-template-packages.cjs", + "validate:templates": "node scripts/validate-template-packages.cjs && pnpm --filter @personal-brand/template-contract test", + "generate:template-catalog": "node scripts/generate-template-catalog.cjs --write", "template:dev": "node packages/template-compiler/src/cli.mjs --template", "validate:template-release": "node scripts/validate-template-release.cjs", "test:template-compiler": "pnpm --filter @personal-brand/template-compiler test", diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index b06b3f7..733a57f 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -59,6 +59,40 @@ export type BrandPresentationUpdate = Partial< Record > >; + +export interface TemplateAdminField { + key: string; + binding: string; + label: string; + help?: string; + input: "text" | "textarea" | "phone" | "image" | "number"; + required?: boolean; + maxLength?: number; + placeholder?: string; +} + +export interface TemplateAdminSection { + key: string; + title: string; + description: string; + target: "brand" | "offering" | "trust" | "inquiry"; + fields: TemplateAdminField[]; +} + +export interface AdminTemplateContent { + displayName: string; + admin: { sections: TemplateAdminSection[] }; + assetSlots: Array<{ + key: string; + binding: string; + target: "brand" | "offering" | "trust"; + label: string; + help: string; + required: boolean; + kind: "image" | "logo" | "portrait" | "texture"; + aspectRatio?: string; + }>; +} export interface OfferingUpdate { name?: string; description?: string; @@ -630,6 +664,7 @@ export class ApiClient { fields: BrandFieldDefinition[]; offerings: Offering[]; forms: unknown[]; + templateContent: AdminTemplateContent | null; }> { return this.request("/admin/workspace"); } @@ -638,7 +673,13 @@ export class ApiClient { } getAdminReleaseReadiness(): Promise<{ ready: boolean; - checks: Array<{ key: string; label: string; passed: boolean }>; + checks: Array<{ + key: string; + label: string; + passed: boolean; + help?: string; + destination?: string; + }>; }> { return this.request("/admin/releases/readiness"); } diff --git a/packages/config/src/generated-template-packages.d.ts b/packages/config/src/generated-template-packages.d.ts new file mode 100644 index 0000000..4419a30 --- /dev/null +++ b/packages/config/src/generated-template-packages.d.ts @@ -0,0 +1,3 @@ +import type { TemplatePackageManifest } from "./index.js"; +export declare const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[]; +export declare const generatedTemplatePackageRegistryHash: string; diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js new file mode 100644 index 0000000..bcca46b --- /dev/null +++ b/packages/config/src/generated-template-packages.js @@ -0,0 +1,615 @@ +// prettier-ignore +export const generatedTemplatePackageRegistry = [ + { + "packageKey": "acheng-campus-food", + "version": "1.0.0", + "displayName": "阿成校园餐", + "defaultBrandSlug": "default-brand", + "runtimeContract": "1.0", + "supportedIndustryTemplates": [ + "food" + ], + "entrypoints": { + "home": "pages/index/index", + "offerings": "pages/services/index", + "service": "pages/stall-service/index", + "detail": "pages/offering/detail", + "inquiry": "pages/inquiry/index", + "success": "pages/inquiry-success/index", + "records": "pages/records/index", + "profile": "pages/bookings/index" + }, + "navigation": [ + { + "key": "home", + "label": "首页/摊位", + "page": "home", + "iconPath": "assets/tab/home.png", + "selectedIconPath": "assets/tab/home-selected.png" + }, + { + "key": "dishes", + "label": "套餐餐品", + "page": "offerings", + "iconPath": "assets/tab/dishes.png", + "selectedIconPath": "assets/tab/dishes-selected.png" + }, + { + "key": "service", + "label": "出摊服务", + "page": "service", + "iconPath": "assets/tab/service.png", + "selectedIconPath": "assets/tab/service-selected.png" + }, + { + "key": "owner", + "label": "主理人", + "page": "profile", + "iconPath": "assets/tab/owner.png", + "selectedIconPath": "assets/tab/owner-selected.png" + }, + { + "key": "booking", + "label": "定制/咨询", + "page": "inquiry", + "iconPath": "assets/tab/booking.png", + "selectedIconPath": "assets/tab/booking-selected.png" + } + ], + "requiredCapabilities": [ + "offerings", + "inquiry", + "booking" + ], + "dataSlots": [ + { + "key": "brand.identity", + "source": "brand", + "required": true, + "description": "摊位名称、主理人和公开联系方式" + }, + { + "key": "brand.hero", + "source": "brand", + "required": true, + "description": "出摊现场和首页营业信息" + }, + { + "key": "trust.proof", + "source": "trust", + "required": true, + "description": "卫生、履约和订餐信任内容" + }, + { + "key": "offerings.list", + "source": "offering", + "required": true, + "description": "今日餐品、套餐和定制服务" + }, + { + "key": "offering.detail", + "source": "offering", + "required": true, + "description": "单个餐品或定制服务详情" + }, + { + "key": "inquiry.form", + "source": "inquiry", + "required": true, + "description": "预订和定制咨询问题" + }, + { + "key": "records.items", + "source": "records", + "required": true, + "description": "访客自己的预订记录" + } + ], + "assetSlots": [ + { + "key": "brand.portrait", + "binding": "brand.avatarUrl", + "target": "brand", + "label": "主理人照片", + "help": "用于首页和主理人页,建议使用清晰正面照片。", + "required": false, + "kind": "portrait", + "aspectRatio": "1:1" + }, + { + "key": "brand.stallHero", + "binding": "brand.config.heroImage", + "target": "brand", + "label": "出摊现场主图", + "help": "展示真实摊位、餐品或取餐场景,避免使用无关的通用图片。", + "required": true, + "kind": "image", + "aspectRatio": "16:9" + }, + { + "key": "offering.cover", + "binding": "offering.coverUrl", + "target": "offering", + "label": "餐品或服务封面", + "help": "每项餐品或服务使用一张清晰图片,方便访客快速选择。", + "required": true, + "kind": "image", + "aspectRatio": "1:1" + } + ], + "admin": { + "sections": [ + { + "key": "identity", + "title": "摊位与主理人", + "description": "让访客知道谁在出餐、在哪里可以找到你。", + "target": "brand", + "fields": [ + { + "key": "founder", + "binding": "brand.config.founder", + "label": "主理人姓名", + "input": "text", + "required": true, + "placeholder": "例如:阿成" + }, + { + "key": "portrait", + "binding": "brand.config.avatarUrl", + "label": "主理人照片", + "help": "使用清晰、真实的照片,让顾客知道是谁在认真做餐。", + "input": "image" + }, + { + "key": "title", + "binding": "brand.config.title", + "label": "你的身份", + "help": "例如:校园餐饮主理人。", + "input": "text", + "required": true + }, + { + "key": "slogan", + "binding": "brand.config.slogan", + "label": "想对顾客说的一句话", + "input": "textarea", + "maxLength": 80 + }, + { + "key": "studioAddress", + "binding": "brand.config.studioAddress", + "label": "出摊地点或服务范围", + "input": "text", + "required": true + }, + { + "key": "phone", + "binding": "brand.config.phone", + "label": "公开联系电话", + "input": "phone" + }, + { + "key": "wechat", + "binding": "brand.config.wechat", + "label": "公开微信号", + "input": "text" + } + ] + }, + { + "key": "home", + "title": "首页出摊信息", + "description": "说明今天在哪里、何时营业,以及餐品有什么特点。", + "target": "brand", + "fields": [ + { + "key": "stallTitle", + "binding": "brand.config.visualPresentation.home.stallTitle", + "label": "出摊信息标题", + "input": "text", + "placeholder": "例如:今日出摊点" + }, + { + "key": "heroImage", + "binding": "brand.config.heroImage", + "label": "出摊现场主图", + "help": "展示真实摊位、餐品或取餐场景,建议使用横向图片。", + "input": "image", + "required": true + }, + { + "key": "stallTime", + "binding": "brand.config.visualPresentation.home.stallTime", + "label": "营业时间说明", + "input": "text", + "placeholder": "例如:17:00 - 22:30 · 今日营业中" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.home.worksTitle", + "label": "招牌餐品标题", + "input": "text" + }, + { + "key": "manifestoTitle", + "binding": "brand.config.visualPresentation.home.manifestoTitle", + "label": "出餐承诺标题", + "input": "text" + } + ] + }, + { + "key": "menu", + "title": "菜单页说明", + "description": "帮助顾客理解日常餐品和团体定制的选择方式。", + "target": "brand", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.offerings.title", + "label": "菜单页标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.offerings.subtitle", + "label": "菜单页说明", + "input": "textarea", + "maxLength": 120 + } + ] + }, + { + "key": "booking", + "title": "预订与定制", + "description": "告诉顾客提交信息后会如何确认餐品和时间。", + "target": "inquiry", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.inquiry.title", + "label": "预订页面标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.inquiry.subtitle", + "label": "预订说明", + "input": "textarea", + "maxLength": 120 + }, + { + "key": "submitLabel", + "binding": "brand.config.visualPresentation.inquiry.submitLabel", + "label": "提交按钮文字", + "input": "text", + "placeholder": "例如:提交预订需求" + } + ] + } + ] + }, + "renderers": { + "home": "acheng-home", + "offerings": "acheng-offerings", + "profile": "acheng-profile" + }, + "runtimeOwnedPages": [ + "detail", + "inquiry", + "success", + "records" + ], + "ownedPaths": [ + "components/templates/acheng-home", + "components/templates/acheng-offerings", + "components/templates/acheng-profile", + "pages/index", + "pages/services", + "pages/bookings", + "pages/inquiry", + "pages/stall-service", + "pages/offering", + "pages/inquiry-success", + "pages/records" + ], + "visualTemplateKey": "acheng-campus-food" + }, + { + "packageKey": "linjing-editorial", + "version": "1.0.0", + "displayName": "林境建筑画册", + "defaultBrandSlug": "linjing-doors", + "runtimeContract": "1.0", + "supportedIndustryTemplates": [ + "personal", + "doors" + ], + "entrypoints": { + "home": "pages/index/index", + "offerings": "pages/services/index", + "detail": "pages/offering/detail", + "inquiry": "pages/inquiry/index", + "success": "pages/inquiry-success/index", + "records": "pages/records/index", + "profile": "pages/bookings/index" + }, + "navigation": [ + { + "key": "home", + "label": "首页", + "page": "home", + "iconPath": "assets/tab/home.png", + "selectedIconPath": "assets/tab/home-selected.png" + }, + { + "key": "offerings", + "label": "案例与体系", + "page": "offerings", + "iconPath": "assets/tab/works.png", + "selectedIconPath": "assets/tab/works-selected.png" + }, + { + "key": "profile", + "label": "主理人与我", + "page": "profile", + "iconPath": "assets/tab/profile.png", + "selectedIconPath": "assets/tab/profile-selected.png" + } + ], + "requiredCapabilities": [ + "offerings", + "inquiry" + ], + "dataSlots": [ + { + "key": "brand.identity", + "source": "brand", + "required": true, + "description": "品牌名称、主理人和公开联系方式" + }, + { + "key": "brand.hero", + "source": "brand", + "required": true, + "description": "建筑项目或产品系统的首页表达" + }, + { + "key": "trust.proof", + "source": "trust", + "required": true, + "description": "资质、方法、项目经验和履约说明" + }, + { + "key": "offerings.list", + "source": "offering", + "required": true, + "description": "门系统案例和服务体系" + }, + { + "key": "offering.detail", + "source": "offering", + "required": true, + "description": "单个项目案例的完整介绍" + }, + { + "key": "inquiry.form", + "source": "inquiry", + "required": true, + "description": "私宅门系统咨询问题" + }, + { + "key": "records.items", + "source": "records", + "required": true, + "description": "访客自己的咨询记录" + } + ], + "assetSlots": [ + { + "key": "brand.portrait", + "binding": "brand.avatarUrl", + "target": "brand", + "label": "主理人肖像", + "help": "用于主理人与我页面,建议使用正式、清晰的照片。", + "required": false, + "kind": "portrait", + "aspectRatio": "1:1" + }, + { + "key": "brand.projectHero", + "binding": "brand.config.heroImage", + "target": "brand", + "label": "首页项目主图", + "help": "展示真实别墅、入户门或空间细节,体现品牌审美和项目能力。", + "required": true, + "kind": "image", + "aspectRatio": "16:9" + }, + { + "key": "offering.cover", + "binding": "offering.coverUrl", + "target": "offering", + "label": "案例封面", + "help": "每个案例使用一张项目实拍或可信效果图。", + "required": true, + "kind": "image", + "aspectRatio": "4:3" + } + ], + "admin": { + "sections": [ + { + "key": "identity", + "title": "主理人与联系方式", + "description": "让业主清楚谁负责项目,以及如何联系你。", + "target": "brand", + "fields": [ + { + "key": "founder", + "binding": "brand.config.founder", + "label": "主理人姓名", + "input": "text", + "required": true + }, + { + "key": "portrait", + "binding": "brand.config.avatarUrl", + "label": "主理人肖像", + "help": "建议使用正式、清晰的个人照片。", + "input": "image" + }, + { + "key": "title", + "binding": "brand.config.title", + "label": "身份或职位", + "input": "text", + "required": true, + "placeholder": "例如:别墅门系统主理人" + }, + { + "key": "slogan", + "binding": "brand.config.slogan", + "label": "主理人主张", + "input": "textarea", + "maxLength": 100 + }, + { + "key": "studioAddress", + "binding": "brand.config.studioAddress", + "label": "服务区域或工作室地址", + "input": "text", + "required": true + }, + { + "key": "phone", + "binding": "brand.config.phone", + "label": "公开联系电话", + "input": "phone" + }, + { + "key": "wechat", + "binding": "brand.config.wechat", + "label": "公开微信号", + "input": "text" + } + ] + }, + { + "key": "home", + "title": "首页品牌表达", + "description": "用简洁的语言解释你的项目方法、代表作品和合作流程。", + "target": "brand", + "fields": [ + { + "key": "founderBadge", + "binding": "brand.config.visualPresentation.home.founderBadge", + "label": "主理人标签", + "input": "text", + "placeholder": "例如:亲自主理 / 10 年经验" + }, + { + "key": "heroImage", + "binding": "brand.config.heroImage", + "label": "首页项目主图", + "help": "展示真实别墅、入户门或空间细节,体现项目能力。", + "input": "image", + "required": true + }, + { + "key": "proofTitle", + "binding": "brand.config.visualPresentation.home.proofTitle", + "label": "信任介绍标题", + "input": "text" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.home.worksTitle", + "label": "代表案例标题", + "input": "text" + }, + { + "key": "flowTitle", + "binding": "brand.config.visualPresentation.home.flowTitle", + "label": "项目流程标题", + "input": "text" + } + ] + }, + { + "key": "cases", + "title": "案例与体系", + "description": "说明案例页展示的内容,让业主能快速找到相近项目。", + "target": "offering", + "fields": [ + { + "key": "worksEyebrow", + "binding": "brand.config.visualPresentation.offerings.worksEyebrow", + "label": "案例页辅助标题", + "input": "text" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.offerings.worksTitle", + "label": "案例页主标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.offerings.subtitle", + "label": "案例页说明", + "input": "textarea", + "maxLength": 140 + } + ] + }, + { + "key": "consultation", + "title": "咨询说明", + "description": "明确访客提交后会得到怎样的回应,减少无效咨询。", + "target": "inquiry", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.inquiry.title", + "label": "咨询页面标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.inquiry.subtitle", + "label": "咨询说明", + "input": "textarea", + "maxLength": 140 + }, + { + "key": "submitLabel", + "binding": "brand.config.visualPresentation.inquiry.submitLabel", + "label": "提交按钮文字", + "input": "text" + } + ] + } + ] + }, + "renderers": { + "home": "linjing-home", + "offerings": "linjing-offerings", + "profile": "linjing-profile" + }, + "runtimeOwnedPages": [ + "detail", + "inquiry", + "success", + "records" + ], + "ownedPaths": [ + "components/templates/linjing-home", + "components/templates/linjing-offerings", + "components/templates/linjing-profile" + ], + "visualTemplateKey": "linjing-editorial" + } +]; +export const generatedTemplatePackageRegistryHash = + "ff79864f3873fe627710c092622abd26212a8c25ab52c422ee4e22e95f4d2d73"; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 3c2772f..47a85b7 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -1,5 +1,7 @@ export const configPackageName = "personal-brand-config"; +import { generatedTemplatePackageRegistry } from "./generated-template-packages.js"; + export type BrandTemplateKey = "personal" | "food" | "doors"; export type VisualTemplateKey = "linjing-editorial" | "acheng-campus-food"; export type CapabilityKey = "offerings" | "inquiry" | "booking" | "quote-request"; @@ -93,7 +95,7 @@ export interface VisualTemplateDefinition { version: string; name: string; description: string; - supportedIndustryTemplates: BrandTemplateKey[]; + supportedIndustryTemplates: readonly BrandTemplateKey[]; variants: Record; theme: { colors: Record; radius: Record }; layout?: { home: string[]; offerings: string[]; detail: string[]; profile: string[] }; @@ -187,54 +189,57 @@ export interface TemplatePackageManifest { displayName: string; visualTemplateKey: VisualTemplateKey; runtimeContract: "1.0"; - supportedIndustryTemplates: BrandTemplateKey[]; - entrypoints: Record; - requiredCapabilities: CapabilityKey[]; + supportedIndustryTemplates: readonly BrandTemplateKey[]; + entrypoints: Readonly>; + requiredCapabilities: readonly CapabilityKey[]; + defaultBrandSlug: string; + navigation: readonly { + key: string; + label: string; + page: string; + iconPath?: string; + selectedIconPath?: string; + }[]; + renderers: Readonly>; + runtimeOwnedPages: readonly string[]; + dataSlots: readonly { + key: string; + source: string; + required: boolean; + description: string; + }[]; + assetSlots: readonly { + key: string; + binding: string; + target: "brand" | "offering" | "trust"; + label: string; + help: string; + required: boolean; + }[]; + admin: { + sections: readonly { + key: string; + title: string; + description: string; + target: "brand" | "offering" | "trust" | "inquiry"; + fields: readonly { key: string; binding: string; label: string; required?: boolean }[]; + }[]; + }; } -export const templatePackageRegistry: readonly TemplatePackageManifest[] = [ - { - packageKey: "linjing-editorial", - version: "1.0.0", - displayName: "林境建筑画册", - visualTemplateKey: "linjing-editorial", - runtimeContract: "1.0", - supportedIndustryTemplates: ["personal", "doors"], - entrypoints: { - home: "pages/index/index", - offerings: "pages/services/index", - detail: "pages/offering/detail", - inquiry: "pages/inquiry/index", - success: "pages/inquiry-success/index", - records: "pages/records/index", - profile: "pages/bookings/index", - }, - requiredCapabilities: ["offerings", "inquiry"], - }, - { - packageKey: "acheng-campus-food", - version: "1.0.0", - displayName: "阿成校园餐", - visualTemplateKey: "acheng-campus-food", - runtimeContract: "1.0", - supportedIndustryTemplates: ["food"], - entrypoints: { - home: "pages/index/index", - offerings: "pages/services/index", - detail: "pages/offering/detail", - inquiry: "pages/inquiry/index", - success: "pages/inquiry-success/index", - records: "pages/records/index", - profile: "pages/bookings/index", - }, - requiredCapabilities: ["offerings", "inquiry", "booking"], - }, -]; +export const templatePackageRegistry: readonly TemplatePackageManifest[] = + generatedTemplatePackageRegistry; export function getTemplatePackageManifest(key: string): TemplatePackageManifest | undefined { return templatePackageRegistry.find((item) => item.packageKey === key); } +export function getTemplatePackageManifestForVisualKey( + visualTemplateKey: string, +): TemplatePackageManifest | undefined { + return templatePackageRegistry.find((item) => item.visualTemplateKey === visualTemplateKey); +} + export function validateTemplatePackageManifest(manifest: TemplatePackageManifest): string[] { const errors: string[] = []; if (!manifest.packageKey.trim()) errors.push("packageKey is required"); diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json index 1510b65..00a097b 100644 --- a/packages/template-acheng-campus-food/template.json +++ b/packages/template-acheng-campus-food/template.json @@ -53,6 +53,234 @@ } ], "requiredCapabilities": ["offerings", "inquiry", "booking"], + "dataSlots": [ + { + "key": "brand.identity", + "source": "brand", + "required": true, + "description": "摊位名称、主理人和公开联系方式" + }, + { + "key": "brand.hero", + "source": "brand", + "required": true, + "description": "出摊现场和首页营业信息" + }, + { + "key": "trust.proof", + "source": "trust", + "required": true, + "description": "卫生、履约和订餐信任内容" + }, + { + "key": "offerings.list", + "source": "offering", + "required": true, + "description": "今日餐品、套餐和定制服务" + }, + { + "key": "offering.detail", + "source": "offering", + "required": true, + "description": "单个餐品或定制服务详情" + }, + { + "key": "inquiry.form", + "source": "inquiry", + "required": true, + "description": "预订和定制咨询问题" + }, + { + "key": "records.items", + "source": "records", + "required": true, + "description": "访客自己的预订记录" + } + ], + "assetSlots": [ + { + "key": "brand.portrait", + "binding": "brand.avatarUrl", + "target": "brand", + "label": "主理人照片", + "help": "用于首页和主理人页,建议使用清晰正面照片。", + "required": false, + "kind": "portrait", + "aspectRatio": "1:1" + }, + { + "key": "brand.stallHero", + "binding": "brand.config.heroImage", + "target": "brand", + "label": "出摊现场主图", + "help": "展示真实摊位、餐品或取餐场景,避免使用无关的通用图片。", + "required": true, + "kind": "image", + "aspectRatio": "16:9" + }, + { + "key": "offering.cover", + "binding": "offering.coverUrl", + "target": "offering", + "label": "餐品或服务封面", + "help": "每项餐品或服务使用一张清晰图片,方便访客快速选择。", + "required": true, + "kind": "image", + "aspectRatio": "1:1" + } + ], + "admin": { + "sections": [ + { + "key": "identity", + "title": "摊位与主理人", + "description": "让访客知道谁在出餐、在哪里可以找到你。", + "target": "brand", + "fields": [ + { + "key": "founder", + "binding": "brand.config.founder", + "label": "主理人姓名", + "input": "text", + "required": true, + "placeholder": "例如:阿成" + }, + { + "key": "portrait", + "binding": "brand.config.avatarUrl", + "label": "主理人照片", + "help": "使用清晰、真实的照片,让顾客知道是谁在认真做餐。", + "input": "image" + }, + { + "key": "title", + "binding": "brand.config.title", + "label": "你的身份", + "help": "例如:校园餐饮主理人。", + "input": "text", + "required": true + }, + { + "key": "slogan", + "binding": "brand.config.slogan", + "label": "想对顾客说的一句话", + "input": "textarea", + "maxLength": 80 + }, + { + "key": "studioAddress", + "binding": "brand.config.studioAddress", + "label": "出摊地点或服务范围", + "input": "text", + "required": true + }, + { + "key": "phone", + "binding": "brand.config.phone", + "label": "公开联系电话", + "input": "phone" + }, + { + "key": "wechat", + "binding": "brand.config.wechat", + "label": "公开微信号", + "input": "text" + } + ] + }, + { + "key": "home", + "title": "首页出摊信息", + "description": "说明今天在哪里、何时营业,以及餐品有什么特点。", + "target": "brand", + "fields": [ + { + "key": "stallTitle", + "binding": "brand.config.visualPresentation.home.stallTitle", + "label": "出摊信息标题", + "input": "text", + "placeholder": "例如:今日出摊点" + }, + { + "key": "heroImage", + "binding": "brand.config.heroImage", + "label": "出摊现场主图", + "help": "展示真实摊位、餐品或取餐场景,建议使用横向图片。", + "input": "image", + "required": true + }, + { + "key": "stallTime", + "binding": "brand.config.visualPresentation.home.stallTime", + "label": "营业时间说明", + "input": "text", + "placeholder": "例如:17:00 - 22:30 · 今日营业中" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.home.worksTitle", + "label": "招牌餐品标题", + "input": "text" + }, + { + "key": "manifestoTitle", + "binding": "brand.config.visualPresentation.home.manifestoTitle", + "label": "出餐承诺标题", + "input": "text" + } + ] + }, + { + "key": "menu", + "title": "菜单页说明", + "description": "帮助顾客理解日常餐品和团体定制的选择方式。", + "target": "brand", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.offerings.title", + "label": "菜单页标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.offerings.subtitle", + "label": "菜单页说明", + "input": "textarea", + "maxLength": 120 + } + ] + }, + { + "key": "booking", + "title": "预订与定制", + "description": "告诉顾客提交信息后会如何确认餐品和时间。", + "target": "inquiry", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.inquiry.title", + "label": "预订页面标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.inquiry.subtitle", + "label": "预订说明", + "input": "textarea", + "maxLength": 120 + }, + { + "key": "submitLabel", + "binding": "brand.config.visualPresentation.inquiry.submitLabel", + "label": "提交按钮文字", + "input": "text", + "placeholder": "例如:提交预订需求" + } + ] + } + ] + }, "renderers": { "home": "acheng-home", "offerings": "acheng-offerings", diff --git a/packages/template-compiler/src/cli.mjs b/packages/template-compiler/src/cli.mjs index 9968b47..374e7f0 100644 --- a/packages/template-compiler/src/cli.mjs +++ b/packages/template-compiler/src/cli.mjs @@ -22,6 +22,20 @@ function validateManifest(manifest) { } if (!Array.isArray(manifest.navigation) || !manifest.navigation.length) throw new Error("template.json navigation must not be empty"); + if (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length) + throw new Error("template.json dataSlots must not be empty"); + if (!Array.isArray(manifest.assetSlots)) + throw new Error("template.json assetSlots must be an array"); + if (!manifest.admin || !Array.isArray(manifest.admin.sections) || !manifest.admin.sections.length) + throw new Error("template.json admin.sections must not be empty"); + for (const section of manifest.admin.sections) { + if (!section.key || !section.title || !section.description || !Array.isArray(section.fields)) + throw new Error("template.json admin sections require key, title, description and fields"); + for (const field of section.fields) { + if (!field.key || !field.binding || !field.label || !field.input) + throw new Error("template.json admin fields require key, binding, label and input"); + } + } if ( manifest.renderers !== undefined && (typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers)) diff --git a/packages/template-contract/package.json b/packages/template-contract/package.json index 5ec707f..5ed7e66 100644 --- a/packages/template-contract/package.json +++ b/packages/template-contract/package.json @@ -7,6 +7,7 @@ ".": "./src/index.ts" }, "scripts": { - "typecheck": "tsc -p tsconfig.json --noEmit" + "typecheck": "tsc -p tsconfig.json --noEmit", + "test": "node --experimental-strip-types --test test/*.test.mjs" } } diff --git a/packages/template-contract/src/index.ts b/packages/template-contract/src/index.ts index 8506ffa..f90dec7 100644 --- a/packages/template-contract/src/index.ts +++ b/packages/template-contract/src/index.ts @@ -7,6 +7,59 @@ export type TemplateRenderers = Partial { + const manifestPath = path.join(packageRoot, `template-${key}`, "template.json"); + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); + assert.deepEqual(validateTemplatePackageManifest(manifest), []); + }); +} + +test("template contract rejects technical or incomplete admin declarations", () => { + const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json"); + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); + manifest.admin.sections[0].fields[0].label = ""; + manifest.assetSlots[0].help = ""; + assert.deepEqual(validateTemplatePackageManifest(manifest), [ + "every asset slot requires key, binding, label and help", + "every admin field requires key, binding and label", + ]); +}); diff --git a/packages/template-linjing-editorial/template.json b/packages/template-linjing-editorial/template.json index 8bcd497..ff5995f 100644 --- a/packages/template-linjing-editorial/template.json +++ b/packages/template-linjing-editorial/template.json @@ -38,6 +38,237 @@ } ], "requiredCapabilities": ["offerings", "inquiry"], + "dataSlots": [ + { + "key": "brand.identity", + "source": "brand", + "required": true, + "description": "品牌名称、主理人和公开联系方式" + }, + { + "key": "brand.hero", + "source": "brand", + "required": true, + "description": "建筑项目或产品系统的首页表达" + }, + { + "key": "trust.proof", + "source": "trust", + "required": true, + "description": "资质、方法、项目经验和履约说明" + }, + { + "key": "offerings.list", + "source": "offering", + "required": true, + "description": "门系统案例和服务体系" + }, + { + "key": "offering.detail", + "source": "offering", + "required": true, + "description": "单个项目案例的完整介绍" + }, + { + "key": "inquiry.form", + "source": "inquiry", + "required": true, + "description": "私宅门系统咨询问题" + }, + { + "key": "records.items", + "source": "records", + "required": true, + "description": "访客自己的咨询记录" + } + ], + "assetSlots": [ + { + "key": "brand.portrait", + "binding": "brand.avatarUrl", + "target": "brand", + "label": "主理人肖像", + "help": "用于主理人与我页面,建议使用正式、清晰的照片。", + "required": false, + "kind": "portrait", + "aspectRatio": "1:1" + }, + { + "key": "brand.projectHero", + "binding": "brand.config.heroImage", + "target": "brand", + "label": "首页项目主图", + "help": "展示真实别墅、入户门或空间细节,体现品牌审美和项目能力。", + "required": true, + "kind": "image", + "aspectRatio": "16:9" + }, + { + "key": "offering.cover", + "binding": "offering.coverUrl", + "target": "offering", + "label": "案例封面", + "help": "每个案例使用一张项目实拍或可信效果图。", + "required": true, + "kind": "image", + "aspectRatio": "4:3" + } + ], + "admin": { + "sections": [ + { + "key": "identity", + "title": "主理人与联系方式", + "description": "让业主清楚谁负责项目,以及如何联系你。", + "target": "brand", + "fields": [ + { + "key": "founder", + "binding": "brand.config.founder", + "label": "主理人姓名", + "input": "text", + "required": true + }, + { + "key": "portrait", + "binding": "brand.config.avatarUrl", + "label": "主理人肖像", + "help": "建议使用正式、清晰的个人照片。", + "input": "image" + }, + { + "key": "title", + "binding": "brand.config.title", + "label": "身份或职位", + "input": "text", + "required": true, + "placeholder": "例如:别墅门系统主理人" + }, + { + "key": "slogan", + "binding": "brand.config.slogan", + "label": "主理人主张", + "input": "textarea", + "maxLength": 100 + }, + { + "key": "studioAddress", + "binding": "brand.config.studioAddress", + "label": "服务区域或工作室地址", + "input": "text", + "required": true + }, + { + "key": "phone", + "binding": "brand.config.phone", + "label": "公开联系电话", + "input": "phone" + }, + { + "key": "wechat", + "binding": "brand.config.wechat", + "label": "公开微信号", + "input": "text" + } + ] + }, + { + "key": "home", + "title": "首页品牌表达", + "description": "用简洁的语言解释你的项目方法、代表作品和合作流程。", + "target": "brand", + "fields": [ + { + "key": "founderBadge", + "binding": "brand.config.visualPresentation.home.founderBadge", + "label": "主理人标签", + "input": "text", + "placeholder": "例如:亲自主理 / 10 年经验" + }, + { + "key": "heroImage", + "binding": "brand.config.heroImage", + "label": "首页项目主图", + "help": "展示真实别墅、入户门或空间细节,体现项目能力。", + "input": "image", + "required": true + }, + { + "key": "proofTitle", + "binding": "brand.config.visualPresentation.home.proofTitle", + "label": "信任介绍标题", + "input": "text" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.home.worksTitle", + "label": "代表案例标题", + "input": "text" + }, + { + "key": "flowTitle", + "binding": "brand.config.visualPresentation.home.flowTitle", + "label": "项目流程标题", + "input": "text" + } + ] + }, + { + "key": "cases", + "title": "案例与体系", + "description": "说明案例页展示的内容,让业主能快速找到相近项目。", + "target": "offering", + "fields": [ + { + "key": "worksEyebrow", + "binding": "brand.config.visualPresentation.offerings.worksEyebrow", + "label": "案例页辅助标题", + "input": "text" + }, + { + "key": "worksTitle", + "binding": "brand.config.visualPresentation.offerings.worksTitle", + "label": "案例页主标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.offerings.subtitle", + "label": "案例页说明", + "input": "textarea", + "maxLength": 140 + } + ] + }, + { + "key": "consultation", + "title": "咨询说明", + "description": "明确访客提交后会得到怎样的回应,减少无效咨询。", + "target": "inquiry", + "fields": [ + { + "key": "title", + "binding": "brand.config.visualPresentation.inquiry.title", + "label": "咨询页面标题", + "input": "text" + }, + { + "key": "subtitle", + "binding": "brand.config.visualPresentation.inquiry.subtitle", + "label": "咨询说明", + "input": "textarea", + "maxLength": 140 + }, + { + "key": "submitLabel", + "binding": "brand.config.visualPresentation.inquiry.submitLabel", + "label": "提交按钮文字", + "input": "text" + } + ] + } + ] + }, "renderers": { "home": "linjing-home", "offerings": "linjing-offerings", diff --git a/packages/types/src/runtime-workspace.ts b/packages/types/src/runtime-workspace.ts index f1f580c..0bd1e1d 100644 --- a/packages/types/src/runtime-workspace.ts +++ b/packages/types/src/runtime-workspace.ts @@ -94,6 +94,7 @@ export interface RuntimeOffering { crafts: string[]; materialsList: Array<{ name: string; spec: string }>; }; + [key: string]: unknown; }; sections: Array<{ key: string; diff --git a/scripts/generate-template-catalog.cjs b/scripts/generate-template-catalog.cjs new file mode 100644 index 0000000..4e593d7 --- /dev/null +++ b/scripts/generate-template-catalog.cjs @@ -0,0 +1,53 @@ +const fs = require("node:fs"); +const path = require("node:path"); +const crypto = require("node:crypto"); + +const root = path.resolve(__dirname, ".."); +const packageRoot = path.join(root, "packages"); +const outputPath = path.join(root, "packages/config/src/generated-template-packages.js"); +const declarationPath = path.join(root, "packages/config/src/generated-template-packages.d.ts"); +const templates = fs + .readdirSync(packageRoot, { withFileTypes: true }) + .filter( + (entry) => + entry.isDirectory() && + entry.name.startsWith("template-") && + fs.existsSync(path.join(packageRoot, entry.name, "template.json")), + ) + .map((entry) => { + const manifest = JSON.parse( + fs.readFileSync(path.join(packageRoot, entry.name, "template.json"), "utf8"), + ); + return { ...manifest, visualTemplateKey: manifest.packageKey }; + }) + .sort((left, right) => left.packageKey.localeCompare(right.packageKey)); + +const canonical = (value) => { + if (Array.isArray(value)) return value.map(canonical); + if (!value || typeof value !== "object") return value; + return Object.fromEntries( + Object.keys(value) + .sort() + .map((key) => [key, canonical(value[key])]), + ); +}; +const fingerprint = crypto + .createHash("sha256") + .update(JSON.stringify(canonical(templates))) + .digest("hex"); +const content = `// prettier-ignore\nexport const generatedTemplatePackageRegistry = ${JSON.stringify(templates, null, 2)};\nexport const generatedTemplatePackageRegistryHash =\n "${fingerprint}";\n`; +const declaration = `import type { TemplatePackageManifest } from "./index.js";\nexport declare const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[];\nexport declare const generatedTemplatePackageRegistryHash: string;\n`; +const write = process.argv.includes("--write"); +if (write) { + fs.writeFileSync(outputPath, content); + fs.writeFileSync(declarationPath, declaration); +} else { + const current = fs.existsSync(outputPath) ? fs.readFileSync(outputPath, "utf8") : ""; + const generatedHash = current.match( + /generatedTemplatePackageRegistryHash\s*=\s*"([a-f0-9]+)"/, + )?.[1]; + if (generatedHash !== fingerprint) { + console.error("Generated template catalog is stale. Run pnpm generate:template-catalog."); + process.exit(1); + } +} diff --git a/scripts/validate-template-packages.cjs b/scripts/validate-template-packages.cjs index d6e6b61..d55209c 100644 --- a/scripts/validate-template-packages.cjs +++ b/scripts/validate-template-packages.cjs @@ -2,6 +2,7 @@ const fs = require("node:fs"); const path = require("node:path"); const root = path.resolve(__dirname, ".."); +require(path.join(root, "scripts/generate-template-catalog.cjs")); const packageRoot = path.join(root, "templates"); const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"]; const errors = []; @@ -74,6 +75,16 @@ for (const entry of workspaceTemplates) { if (!manifest.displayName) errors.push(`${entry.name}: displayName is required`); if (!Array.isArray(manifest.navigation) || !manifest.navigation.length) errors.push(`${entry.name}: navigation is required`); + if (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length) + errors.push(`${entry.name}: dataSlots is required`); + if (!Array.isArray(manifest.assetSlots)) + errors.push(`${entry.name}: assetSlots must be an array`); + if ( + !manifest.admin || + !Array.isArray(manifest.admin.sections) || + !manifest.admin.sections.length + ) + errors.push(`${entry.name}: admin.sections is required`); if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths)) errors.push(`${entry.name}: ownedPaths must be an array`); if (