refactor(core): keep plan prices, cloud quotas and public URLs in one contract (WS-A)

Prices, quotas and site URLs were copied by hand into the edge functions,
admin, desktop and the landing site, and the copies disagreed (Payple billed
9,900/29,900 KRW, admin labels said 12,900/24,900 KRW and $9.9/$19.9, the
site said 2,900/8,900 KRW).

- packages/core/src/plan-catalog.ts is the single source for PLAN_PRICE_KRW
  (Free 0 / Pro 2,900 / Pro+ 8,900 a month) and PLAN_QUOTA.
- packages/core/src/web-urls.ts is the single source for the public origin,
  the /app web-app base path, SITE_URLS and billingUrl().
- Deno cannot bundle packages/core, so scripts/ci/sync-core-contract.mjs
  generates _shared/core-contract.generated.ts; `npm run contract:check`
  fails on drift (same pattern as version:sync).
- Payple checkout, renewal and webhook amount checks now bill the catalog
  price, so existing subscribers move to the new price at their next renewal.
  quota.ts, team-contract.ts and the tests read the generated values.
- Admin MRR/ARR is computed in KRW from the catalog; license labels, the
  release link and desktop PREMIUM_LLM limits derive from core; the site
  imports prices and quotas directly.

Policy: docs/REFACTOR_POLICY.md Wave 3, W3-1 and W3-2.
This commit is contained in:
Yun Chan 2026-09-26 15:48:18 +09:00
parent e689683b72
commit 88f24d84a1
21 changed files with 568 additions and 152 deletions

View file

@ -22,11 +22,12 @@ export default async function AdminOverviewPage(): Promise<React.ReactElement> {
}
}
const krw = new Intl.NumberFormat('ko-KR', { style: 'currency', currency: 'KRW', maximumFractionDigits: 0 })
const revenueCards = revenue
? [
{
title: 'Annual Recurring Revenue',
value: `$${revenue.arrUsd.toLocaleString()}`,
value: krw.format(revenue.arrKrw),
subtext: 'Active subscriptions × 12 months',
color: 'green' as const,
badge: 'ARR',
@ -34,7 +35,7 @@ export default async function AdminOverviewPage(): Promise<React.ReactElement> {
},
{
title: 'Monthly Recurring Revenue',
value: `$${revenue.mrrUsd.toLocaleString()}`,
value: krw.format(revenue.mrrKrw),
subtext: `Pro ${revenue.tierBreakdown.pro.toLocaleString()} · Pro+ ${revenue.tierBreakdown.pro_plus.toLocaleString()}`,
color: 'blue' as const,
badge: 'MRR',
@ -208,7 +209,7 @@ export default async function AdminOverviewPage(): Promise<React.ReactElement> {
>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', mb: 2 }}>
<StatRing color={card.color} size={46}>
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '13px', fontWeight: 500 }}>$</Typography>
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '13px', fontWeight: 500 }}>₩</Typography>
</StatRing>
<Box component="span" sx={statusBadgeSx(card.badgeColor)}>
{card.badge}

View file

@ -3,6 +3,7 @@
import { Box, Typography, Button } from '@mui/material'
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
import { SITE_URLS } from '@d3ro/core/web-urls'
import { C, FONT_SANS, FONT_MONO, panelSx, tableSx, statusBadgeSx } from '@/lib/console-theme'
import { requireManager } from '@/lib/admin-guard'
import { fetchReleaseHub, type ReleaseAssetPlatform, type ReleaseHub } from '@/lib/forgejo-releases'
@ -107,7 +108,7 @@ function HeaderBar({ feedLive, repoHtmlUrl }: { feedLive: boolean; repoHtmlUrl:
Forgejo Releases ↗
</Button>
<Button
href="https://d3ro.chanpaca.net/download.html"
href={SITE_URLS.download}
target="_blank"
variant="outlined"
sx={{

View file

@ -20,9 +20,12 @@ import {
Alert
} from '@mui/material'
import type { LicenseTier } from '@d3ro/core/types'
import { PLAN_PRICE_KRW } from '@d3ro/core/plan-catalog'
import { d3roPalette, d3roFontMono, d3roRadius } from '@d3ro/ui/theme'
import { C, FONT_SANS, FONT_MONO, primaryButtonSx } from '@/lib/console-theme'
const krw = new Intl.NumberFormat('ko-KR', { style: 'currency', currency: 'KRW', maximumFractionDigits: 0 })
interface LicenseIssuerDialogProps {
open: boolean
onClose: () => void
@ -150,9 +153,9 @@ export function LicenseIssuerDialog({ open, onClose }: LicenseIssuerDialogProps)
<FormControl fullWidth sx={inputSx}>
<InputLabel>Plan / Tier</InputLabel>
<Select value={tier} onChange={(e) => setTier(e.target.value as LicenseTier)} label="Plan / Tier">
<MenuItem value="pro">Pro ($9.9 / ₩12,900)</MenuItem>
<MenuItem value="pro_plus">Pro+ ($19.9 / ₩24,900)</MenuItem>
<MenuItem value="team">Team ($25 / ₩32,000)</MenuItem>
<MenuItem value="pro">Pro ({krw.format(PLAN_PRICE_KRW.pro)} / month)</MenuItem>
<MenuItem value="pro_plus">Pro+ ({krw.format(PLAN_PRICE_KRW.pro_plus)} / month)</MenuItem>
<MenuItem value="team">Team</MenuItem>
<MenuItem value="enterprise">Enterprise (Custom)</MenuItem>
</Select>
</FormControl>

View file

@ -1,17 +1,12 @@
import 'server-only'
import { PLAN_PRICE_KRW } from '@d3ro/core/plan-catalog'
import { getSupabaseAdminClient } from './supabase-admin'
/** Monthly list price per tier, in USD. */
const TIER_MONTHLY_USD: Record<'pro' | 'pro_plus' | 'free', number> = {
pro: 9.9,
pro_plus: 19.9,
free: 0,
}
export interface SubscriptionRevenue {
mrrUsd: number
arrUsd: number
/** Monthly list-price revenue in KRW (PLAN_PRICE_KRW; provider currency is not tracked per row). */
mrrKrw: number
arrKrw: number
activeCount: number
tierBreakdown: { pro: number; pro_plus: number; free: number }
}
@ -19,7 +14,7 @@ export interface SubscriptionRevenue {
/**
* Aggregates real subscription revenue from Supabase.
* Only status === 'active' subscriptions contribute to MRR/ARR.
* MRR = Σ(monthly price of each active subscription's tier); ARR = MRR * 12.
* MRR = Σ(PLAN_PRICE_KRW of each active subscription's tier); ARR = MRR * 12.
*/
export async function fetchSubscriptionRevenue(): Promise<SubscriptionRevenue> {
const supabase = await getSupabaseAdminClient('manager')
@ -37,7 +32,7 @@ export async function fetchSubscriptionRevenue(): Promise<SubscriptionRevenue> {
}
const tierBreakdown = { pro: 0, pro_plus: 0, free: 0 }
let mrrUsd = 0
let mrrKrw = 0
let activeCount = 0
for (const row of rows) {
@ -46,12 +41,9 @@ export async function fetchSubscriptionRevenue(): Promise<SubscriptionRevenue> {
const tier = row.tier
if (tier === 'pro' || tier === 'pro_plus' || tier === 'free') {
tierBreakdown[tier] += 1
mrrUsd += TIER_MONTHLY_USD[tier]
mrrKrw += PLAN_PRICE_KRW[tier]
}
}
mrrUsd = Math.round(mrrUsd * 100) / 100
const arrUsd = Math.round(mrrUsd * 12 * 100) / 100
return { mrrUsd, arrUsd, activeCount, tierBreakdown }
return { mrrKrw, arrKrw: mrrKrw * 12, activeCount, tierBreakdown }
}

View file

@ -20,6 +20,7 @@ import type {
} from '@d3ro/core/types'
import { Feature } from '@d3ro/core/types'
import { normalizeEntitlementTier } from '@d3ro/core/entitlement'
import { PLAN_QUOTA } from '@d3ro/core/plan-catalog'
import { verifySignedLicenseKey, createDefaultTrialPayload } from '@d3ro/core/utils/crypto-license'
const logger = getLogger('license')
@ -56,20 +57,22 @@ function generateMachineId(): string {
// 클라이언트에서는 PREMIUM_LLM feature로 묶어서 canUse() 체크하고,
// 실제 모델별 세분화는 서버 llm-proxy가 담당.
// 여기의 값은 Settings UI 표시용 + upgrade 유도 시점 판단용.
const QUOTA_LIMITS: Record<LicenseTier, Partial<Record<Feature, number>>> = {
free: {
// Haiku만, 250/주간. 클라이언트에서는 대략적 일환산(~36/일)으로 표시.
[Feature.PREMIUM_LLM]: 250,
},
pro: {
// 모델별: Haiku 1500 + Sonnet 300 + Opus 50 = 합산 표시
[Feature.PREMIUM_LLM]: 1850,
},
pro_plus: {},
team: {},
enterprise: {},
// 값의 정본은 @d3ro/core PLAN_QUOTA. PREMIUM_LLM은 모델별 한도의 합으로 표시하고,
// 한 모델이라도 무제한이면 한도를 두지 않는다(Free는 Haiku 주 250회).
function premiumLlmLimit(tier: LicenseTier): number | undefined {
const quota = PLAN_QUOTA[tier]
const models = [quota.llm_haiku, quota.llm_sonnet, quota.llm_opus].filter((q) => q.limit !== 0)
if (models.some((q) => q.limit < 0)) return undefined
return models.reduce((sum, q) => sum + q.limit, 0)
}
const QUOTA_LIMITS: Record<LicenseTier, Partial<Record<Feature, number>>> = Object.fromEntries(
(['free', 'pro', 'pro_plus', 'team', 'enterprise'] as const).map((tier) => {
const limit = premiumLlmLimit(tier)
return [tier, limit === undefined ? {} : { [Feature.PREMIUM_LLM]: limit }]
}),
) as Record<LicenseTier, Partial<Record<Feature, number>>>
// ── 기능별 최소 필요 티어 ──────────────────────────────────
// 빅뱅 Phase 4: 모든 로컬 기능을 'free'로 해방.
// 클라우드 기능(PREMIUM_LLM, CLOUD_SYNC)만 로그인 요구 + 티어 gate.