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.
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import {
|
|
createBillingCatalog,
|
|
parseStripeCatalogPrice,
|
|
} from './billing-catalog.ts'
|
|
import { PLAN_PRICE_KRW } from './core-contract.generated.ts'
|
|
|
|
function assert(condition: unknown, message: string): asserts condition {
|
|
if (!condition) throw new Error(message)
|
|
}
|
|
|
|
Deno.test('Stripe catalog accepts only the exact active recurring price', () => {
|
|
const parsed = parseStripeCatalogPrice({
|
|
id: 'price_pro',
|
|
active: true,
|
|
type: 'recurring',
|
|
unit_amount: 990,
|
|
currency: 'usd',
|
|
recurring: { interval: 'month', interval_count: 1 },
|
|
}, 'price_pro')
|
|
assert(parsed?.unit_amount === 990, 'amount must be preserved')
|
|
assert(parsed?.currency === 'USD', 'currency must be normalized')
|
|
assert(parsed?.interval === 'month', 'interval must be preserved')
|
|
})
|
|
|
|
Deno.test('Stripe catalog rejects mismatched, inactive, free, malformed, and one-time prices', () => {
|
|
const base = {
|
|
id: 'price_pro',
|
|
active: true,
|
|
type: 'recurring',
|
|
unit_amount: 990,
|
|
currency: 'usd',
|
|
recurring: { interval: 'month', interval_count: 1 },
|
|
}
|
|
const invalid = [
|
|
{ ...base, id: 'price_other' },
|
|
{ ...base, active: false },
|
|
{ ...base, type: 'one_time', recurring: null },
|
|
{ ...base, unit_amount: 0 },
|
|
{ ...base, currency: 'US$' },
|
|
{ ...base, recurring: { interval: 'minute', interval_count: 1 } },
|
|
{ ...base, recurring: { interval: 'month', interval_count: 0 } },
|
|
]
|
|
for (const value of invalid) {
|
|
assert(parseStripeCatalogPrice(value, 'price_pro') === null, 'invalid Stripe price must fail closed')
|
|
}
|
|
})
|
|
|
|
Deno.test('catalog exposes only configured provider prices and never invents a fallback', () => {
|
|
const catalog = createBillingCatalog({
|
|
payple: { pro: PLAN_PRICE_KRW.pro, pro_plus: PLAN_PRICE_KRW.pro_plus },
|
|
stripe: {
|
|
pro: { unit_amount: 990, currency: 'USD', interval: 'month', interval_count: 1 },
|
|
},
|
|
})
|
|
assert(catalog.plans[0].prices.length === 2, 'pro must expose two verified providers')
|
|
assert(catalog.plans[1].prices.length === 1, 'pro plus must omit unavailable Stripe')
|
|
assert(
|
|
catalog.plans[0].prices[0].unit_amount === PLAN_PRICE_KRW.pro
|
|
&& catalog.plans[1].prices[0].unit_amount === PLAN_PRICE_KRW.pro_plus,
|
|
'Payple prices must come from the core plan catalog',
|
|
)
|
|
|
|
const unavailable = createBillingCatalog({})
|
|
assert(unavailable.plans.every((plan) => plan.prices.length === 0), 'missing configuration must stay unavailable')
|
|
})
|