refactor: simplify pricing tables to USD-only

- Remove KRW pricing calculations from all pricing tables
- Simplify pricing table to store only wholesale USD prices
- Simplify anvil_pricing to store only retail USD prices
- Remove KRW environment variables (KRW_EXCHANGE_RATE, KRW_MARGIN_RATE)
- Remove KRW functions from constants.ts
- Update GPU/G8/VPU pricing repositories to match
- Add Anvil tables and repositories for branded product support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-25 21:16:25 +09:00
parent a2133ae5c9
commit 9f3d3a245a
21 changed files with 1952 additions and 197 deletions

View File

@@ -226,88 +226,52 @@ export const REQUEST_LIMITS = {
} as const;
// ============================================================
// KRW Pricing Configuration
// USD Retail Pricing Configuration
// ============================================================
/**
* Default KRW (Korean Won) pricing configuration
* Default USD retail pricing configuration
*
* These defaults are used when environment variables are not set.
* These defaults are used to calculate retail prices from wholesale prices.
* Calculation formula:
* KRW = USD × VAT (1.1) × Markup (1.1) × Exchange Rate (1450)
* KRW = USD × 1754.5
* Retail = Wholesale × Margin (1.1) × VAT (1.1)
* Retail = Wholesale × 1.21
*/
export const KRW_PRICING_DEFAULTS = {
export const USD_RETAIL_DEFAULTS = {
/** Margin multiplier (10% margin) */
MARGIN_MULTIPLIER: 1.1,
/** VAT multiplier (10% VAT) */
VAT_MULTIPLIER: 1.1,
/** Markup multiplier (10% markup) */
MARKUP_MULTIPLIER: 1.1,
/** USD to KRW exchange rate */
EXCHANGE_RATE: 1450,
/** Total multiplier (margin × VAT) */
TOTAL_MULTIPLIER: 1.21,
} as const;
/**
* KRW pricing configuration interface
*/
export interface KRWConfig {
exchangeRate: number;
vatRate: number;
markupRate: number;
totalMultiplier: number;
}
/**
* Get KRW pricing configuration from environment variables
* Falls back to default values if env vars are not set
* Calculate USD retail hourly price from wholesale price
* Applies margin and VAT
*
* @param env - Cloudflare Worker environment
* @returns KRW pricing configuration
*/
export function getKRWConfig(env?: { KRW_EXCHANGE_RATE?: string; KRW_VAT_RATE?: string; KRW_MARKUP_RATE?: string }): KRWConfig {
const exchangeRate = env?.KRW_EXCHANGE_RATE ? parseFloat(env.KRW_EXCHANGE_RATE) : KRW_PRICING_DEFAULTS.EXCHANGE_RATE;
const vatRate = env?.KRW_VAT_RATE ? parseFloat(env.KRW_VAT_RATE) : KRW_PRICING_DEFAULTS.VAT_MULTIPLIER;
const markupRate = env?.KRW_MARKUP_RATE ? parseFloat(env.KRW_MARKUP_RATE) : KRW_PRICING_DEFAULTS.MARKUP_MULTIPLIER;
return {
exchangeRate,
vatRate,
markupRate,
totalMultiplier: vatRate * markupRate * exchangeRate,
};
}
/**
* Calculate KRW hourly price from USD price
* Applies VAT, markup, and exchange rate conversion
*
* @param usd - Hourly price in USD
* @param env - Optional environment for custom rates (uses defaults if not provided)
* @returns Price in KRW, rounded to nearest 1 KRW (minimum 1 KRW)
* @param wholesale - Wholesale hourly price in USD
* @returns Retail price in USD, rounded to 4 decimal places
*
* @example
* calculateKRWHourly(0.0075) // Returns 13 (with defaults)
* calculateKRWHourly(0.144) // Returns 253 (with defaults)
* calculateRetailHourly(0.0075) // Returns 0.0091 (with defaults)
* calculateRetailHourly(0.144) // Returns 0.1742 (with defaults)
*/
export function calculateKRWHourly(usd: number, env?: { KRW_EXCHANGE_RATE?: string; KRW_VAT_RATE?: string; KRW_MARKUP_RATE?: string }): number {
const config = getKRWConfig(env);
const krw = Math.round(usd * config.totalMultiplier);
return Math.max(krw, 1);
export function calculateRetailHourly(wholesale: number): number {
return Math.round(wholesale * USD_RETAIL_DEFAULTS.TOTAL_MULTIPLIER * 10000) / 10000;
}
/**
* Calculate KRW monthly price from USD price
* Applies VAT, markup, and exchange rate conversion
* Calculate USD retail monthly price from wholesale price
* Applies margin and VAT
*
* @param usd - Monthly price in USD
* @param env - Optional environment for custom rates (uses defaults if not provided)
* @returns Price in KRW, rounded to nearest 100 KRW (minimum 100 KRW)
* @param wholesale - Wholesale monthly price in USD
* @returns Retail price in USD, rounded to nearest $1
*
* @example
* calculateKRWMonthly(5) // Returns 8800 (with defaults)
* calculateKRWMonthly(96) // Returns 168400 (with defaults)
* calculateRetailMonthly(5) // Returns 6 (with defaults)
* calculateRetailMonthly(96) // Returns 116 (with defaults)
*/
export function calculateKRWMonthly(usd: number, env?: { KRW_EXCHANGE_RATE?: string; KRW_VAT_RATE?: string; KRW_MARKUP_RATE?: string }): number {
const config = getKRWConfig(env);
const krw = Math.round(usd * config.totalMultiplier / 100) * 100;
return Math.max(krw, 100);
export function calculateRetailMonthly(wholesale: number): number {
return Math.round(wholesale * USD_RETAIL_DEFAULTS.TOTAL_MULTIPLIER);
}