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

@ -7,6 +7,7 @@ import {
parseTeamInviteInput,
TeamContractError,
} from './team-contract.ts'
import { PUBLIC_SITE_ORIGIN } from './core-contract.generated.ts'
function assert(condition: boolean, message: string): asserts condition {
if (!condition) throw new Error(message)
@ -62,7 +63,7 @@ Deno.test('team accept parser permits only a URL-safe bounded bearer token', ()
Deno.test('site URL is fail-closed to the canonical deployed HTTPS origin', () => {
assert(
normalizeSiteOrigin('https://d3ro.chanpaca.net/app/') === 'https://d3ro.chanpaca.net',
normalizeSiteOrigin(`${PUBLIC_SITE_ORIGIN}/app/`) === PUBLIC_SITE_ORIGIN,
'canonical HTTPS origin must normalize',
)
assertContractError(() => normalizeSiteOrigin(undefined), 'site_url_not_configured', 503)
@ -70,15 +71,15 @@ Deno.test('site URL is fail-closed to the canonical deployed HTTPS origin', () =
assertContractError(() => normalizeSiteOrigin('https://voice.chanpaca.net'), 'site_url_invalid', 503)
assertContractError(() => normalizeSiteOrigin('https://d3ro.dev'), 'site_url_invalid', 503)
assertContractError(() => normalizeSiteOrigin('http://attacker.example'), 'site_url_invalid', 503)
assertContractError(() => normalizeSiteOrigin('https://user:pass@d3ro.chanpaca.net'), 'site_url_invalid', 503)
assertContractError(() => normalizeSiteOrigin(PUBLIC_SITE_ORIGIN.replace('https://', 'https://user:pass@')), 'site_url_invalid', 503)
assertContractError(() => normalizeSiteOrigin('javascript:alert(1)'), 'site_url_invalid', 503)
})
Deno.test('invite URL encodes the token and email HTML escapes every dynamic field', () => {
const token = 'abcdefghijklmnopqrstuvwx_123456'
const url = buildInviteUrl('https://d3ro.chanpaca.net', token)
const url = buildInviteUrl(PUBLIC_SITE_ORIGIN, token)
assert(
url === `https://d3ro.chanpaca.net/accept-invite/?token=${token}`,
url === `${PUBLIC_SITE_ORIGIN}/accept-invite/?token=${token}`,
'canonical invite URL required',
)
const html = buildInviteEmailHtml({