Files
supabase/apps/studio/components/interfaces/Project/ResumeProjectCost.utils.ts
K-Dog (Kevin) 27c4433a3e feat: revised project add-ons page (#54186)
The current add-ons page only lists a subset of available add-ons, which
often causes confusion with things like Advanced MFA Auth (customers
cant find where to configure it).

The revised add-on page covers all potentially configured project
add-ons including replicas and advanced disk. This should help the
customer locate configured add-ons and at the same time discover
potentially interesting add-ons. This can be enhanced further in the
future with "smart" suggestions based on usage.
2026-11-30 21:54:44 +08:00

43 lines
1.2 KiB
TypeScript

/** Compute is billed hourly; the platform prices a full month as 730 hours. */
const BILLABLE_HOURS_PER_MONTH = 730
/** 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,
}
}