nomadro/lib/remote-config.ts
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 23:52:00 -05:00

99 lines
2.3 KiB
TypeScript

/**
* Nomadro remote UI config — backend is source of truth;
* clients ship DEFAULT_REMOTE_CONFIG as offline seed.
*/
export type ModuleToggle = {
enabled: boolean;
title: string;
tabLabel?: string;
note?: string;
};
export type NomadroRemoteConfig = {
version: number;
updatedAt: string;
modules: {
nav: ModuleToggle;
book: ModuleToggle;
community: ModuleToggle;
vip: ModuleToggle;
meetups: ModuleToggle;
destinations: ModuleToggle;
home: ModuleToggle;
};
flags: {
payEnabled: boolean;
socialFollow: boolean;
offlineBadge: boolean;
};
copy: {
homeBrand: string;
homeTagline: string;
homeLead: string;
vipPriceFen: number;
vipProductId: string;
vipCta: string;
};
};
export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
version: 1,
updatedAt: "2026-03-28T00:00:00.000Z",
modules: {
home: { enabled: true, title: "首页", tabLabel: "首页" },
nav: {
enabled: true,
title: "出海导航",
tabLabel: "导航",
note: "apps/navmini links",
},
book: {
enabled: true,
title: "数字游民小册",
tabLabel: "小册",
note: "ebook reader + pay",
},
community: {
enabled: true,
title: "旅居社群",
tabLabel: "社群",
note: "nomadweb",
},
destinations: { enabled: true, title: "目的地" },
meetups: { enabled: true, title: "活动" },
vip: { enabled: true, title: "会员中心", note: "deep link only" },
},
flags: {
payEnabled: true,
socialFollow: true,
offlineBadge: false,
},
copy: {
homeBrand: "nomadro",
homeTagline: "",
homeLead: "",
vipPriceFen: 8800,
vipProductId: "vip_membership",
vipCta: "立即加入",
},
};
export function mergeRemoteConfig(
partial: Partial<NomadroRemoteConfig> | null | undefined,
): NomadroRemoteConfig {
if (!partial || typeof partial !== "object") {
return structuredClone(DEFAULT_REMOTE_CONFIG);
}
const base = structuredClone(DEFAULT_REMOTE_CONFIG);
return {
...base,
...partial,
version: Number(partial.version) || base.version,
updatedAt: partial.updatedAt || base.updatedAt,
modules: { ...base.modules, ...(partial.modules || {}) },
flags: { ...base.flags, ...(partial.flags || {}) },
copy: { ...base.copy, ...(partial.copy || {}) },
};
}