Files
api_user/models/app_registry.js
T
lik efd4e4444c refactor(app): appId wxapp-escort-admin 更名为 wxapp_companion
与陪诊师小程序工程名对齐;同步注册表、配置白名单、脚本示例与测试。数据库 user_app / user_identity / user.app 旧字段已同步迁移。
2026-11-10 16:33:35 +08:00

50 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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;
}