Files
supabase/apps/studio/components/interfaces/Project/ResumeProjectCost.utils.ts
T
K-Dog (Kevin) 5d897958ec feat: project resume costs (#54107)
Currently, when resuming a project, the cost is not clear and we just
have a generic inline "Once resumed, usage will be billed by compute
size and hours active." copy. This commonly leads to people missing that
resuming causing extra compute costs.
2026-11-26 16:03:20 +08:00

43 lines
1.2 KiB
TypeScript

/** Compute is billed hourly; the platform prices a full month as 744 hours. */
const BILLABLE_HOURS_PER_MONTH = 744
/** Compute credit included on every paid plan, applied per organization, not per project. */
export const MONTHLY_COMPUTE_CREDIT = 10
export interface ComputeVariantPrice {
price: number
price_interval: 'monthly' | 'hourly'
}
export const getMonthlyComputePrice = ({ price, price_interval }: ComputeVariantPrice) =>
price_interval === 'hourly' ? price * BILLABLE_HOURS_PER_MONTH : price
export interface ResumeComputeCost {
monthlyPrice: number
/** 0 when another active project in the organization is already using the credit. */
credit: number
monthlyTotal: number
isCovered: boolean
}
/**
* The compute credit only applies when no other project in the organization is active,
* since an active project consumes it first.
*/
export const getResumeComputeCost = ({
monthlyPrice,
hasActiveProjects,
}: {
monthlyPrice: number
hasActiveProjects: boolean
}): ResumeComputeCost => {
const credit = hasActiveProjects ? 0 : Math.min(MONTHLY_COMPUTE_CREDIT, monthlyPrice)
return {
monthlyPrice,
credit,
monthlyTotal: monthlyPrice - credit,
isCovered: monthlyPrice > 0 && credit === monthlyPrice,
}
}