"use strict"; import config from "../conf.json" with { type: "json" }; /** * appId -> 平台/登录方式 元数据 * * conf.json 只放 appid / secret;平台与登录方式放代码里,便于评审与测试。 * 未在 conf.json 配置的应用(ttapp-escort / web-escort-admin / tcm) * 只告警不阻塞启动:它们可能通过密码登录或其他服务写入成员关系。 */ export const APP_REGISTRY = { "wxapp-escort": { platform: "weixin", provider: "weixin-mini" }, "wxapp_companion": { platform: "weixin", provider: "weixin-mini" }, "ttapp-escort": { platform: "douyin", provider: "douyin-mini" }, "web-escort-admin": { platform: "weixin", provider: "weixin-web" }, tcm: { platform: "web", provider: "password" }, }; // 管理端应用:任一应用内的 admin 都视为管理端管理员 export const ADMIN_APP_IDS = ["wxapp_companion", "web-escort-admin"]; // 本阶段只做固定角色白名单,不引入自定义 RBAC export const GRANTABLE_ROLES = ["user", "admin"]; /** * 启动校验:conf.json 中的 appId 必须有元数据;appId 不能含 . 或 $, * 否则会被当成 Mongo 路径写坏文档。 */ export function assertRegistryCoverage() { const configured = Object.keys(config.app || {}); const invalid = configured.filter((id) => !/^[A-Za-z0-9_-]+$/.test(id)); if (invalid.length) { throw new Error(`conf.json 中存在非法 appId(只允许字母、数字、_、-): ${invalid.join(", ")}`); } const missing = configured.filter((id) => !APP_REGISTRY[id]); if (missing.length) { throw new Error(`APP_REGISTRY 缺少 appId 元数据: ${missing.join(", ")}`); } const orphan = Object.keys(APP_REGISTRY).filter((id) => !configured.includes(id)); if (orphan.length) { console.warn(`[user] APP_REGISTRY 中未在 conf.json 配置的 appId: ${orphan.join(", ")}`); } return configured; }