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:
parent
e689683b72
commit
88f24d84a1
21 changed files with 568 additions and 152 deletions
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue