mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
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.
95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import type {
|
|
OrgSubscription,
|
|
PlanId,
|
|
ProjectAddonType,
|
|
ProjectSelectedAddon,
|
|
} from '@/data/subscriptions/types'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export const getAddons = (selectedAddons: ProjectSelectedAddon[]) => {
|
|
const computeInstance = selectedAddons.find((addon) => addon.type === 'compute_instance')
|
|
const pitr = selectedAddons.find((addon) => addon.type === 'pitr')
|
|
const customDomain = selectedAddons.find((addon) => addon.type === 'custom_domain')
|
|
const ipv4 = selectedAddons.find((addon) => addon.type === 'ipv4')
|
|
|
|
return { computeInstance, pitr, customDomain, ipv4 }
|
|
}
|
|
|
|
/** Counts a project's instances of a per-instance add-on (e.g. log drains, pipelines) */
|
|
export const countSelectedAddons = (
|
|
selectedAddons: ProjectSelectedAddon[],
|
|
type: ProjectAddonType
|
|
): number => selectedAddons.filter((addon) => addon.type === type).length
|
|
|
|
export const subscriptionHasHipaaAddon = (subscription?: OrgSubscription): boolean => {
|
|
if (!IS_PLATFORM) return false
|
|
|
|
return (subscription?.addons ?? []).some(
|
|
(addon) => addon.supabase_prod_id === 'addon_security_hipaa'
|
|
)
|
|
}
|
|
|
|
export const billingPartnerLabel = (billingPartner?: string) => {
|
|
if (!billingPartner) return billingPartner
|
|
|
|
switch (billingPartner) {
|
|
case 'aws':
|
|
return 'AWS'
|
|
case 'vercel_marketplace':
|
|
return 'Vercel'
|
|
default:
|
|
return billingPartner
|
|
}
|
|
}
|
|
|
|
export type PlanChangeType = 'upgrade' | 'downgrade' | 'none'
|
|
|
|
export const getPlanChangeType = (
|
|
fromPlan: PlanId | undefined,
|
|
toPlan: PlanId | undefined
|
|
): PlanChangeType => {
|
|
const planChangeTypes: Record<PlanId, Record<PlanId, PlanChangeType>> = {
|
|
free: {
|
|
free: 'none',
|
|
pro: 'upgrade',
|
|
team: 'upgrade',
|
|
enterprise: 'upgrade',
|
|
platform: 'upgrade',
|
|
},
|
|
pro: {
|
|
free: 'downgrade',
|
|
pro: 'none',
|
|
team: 'upgrade',
|
|
enterprise: 'upgrade',
|
|
platform: 'upgrade',
|
|
},
|
|
team: {
|
|
free: 'downgrade',
|
|
pro: 'downgrade',
|
|
team: 'none',
|
|
enterprise: 'upgrade',
|
|
platform: 'upgrade',
|
|
},
|
|
enterprise: {
|
|
free: 'downgrade',
|
|
pro: 'downgrade',
|
|
team: 'downgrade',
|
|
enterprise: 'none',
|
|
platform: 'upgrade',
|
|
},
|
|
platform: {
|
|
free: 'downgrade',
|
|
pro: 'downgrade',
|
|
team: 'downgrade',
|
|
enterprise: 'downgrade',
|
|
platform: 'none',
|
|
},
|
|
}
|
|
|
|
if (!fromPlan || !toPlan) {
|
|
return 'none'
|
|
}
|
|
|
|
return planChangeTypes[fromPlan]?.[toPlan] ?? 'none'
|
|
}
|