Subscription.utils.ts85 lines · main
| 1 | import type { OrgSubscription, PlanId, ProjectSelectedAddon } from '@/data/subscriptions/types' |
| 2 | import { IS_PLATFORM } from '@/lib/constants' |
| 3 | |
| 4 | export const getAddons = (selectedAddons: ProjectSelectedAddon[]) => { |
| 5 | const computeInstance = selectedAddons.find((addon) => addon.type === 'compute_instance') |
| 6 | const pitr = selectedAddons.find((addon) => addon.type === 'pitr') |
| 7 | const customDomain = selectedAddons.find((addon) => addon.type === 'custom_domain') |
| 8 | const ipv4 = selectedAddons.find((addon) => addon.type === 'ipv4') |
| 9 | |
| 10 | return { computeInstance, pitr, customDomain, ipv4 } |
| 11 | } |
| 12 | |
| 13 | export const subscriptionHasHipaaAddon = (subscription?: OrgSubscription): boolean => { |
| 14 | if (!IS_PLATFORM) return false |
| 15 | |
| 16 | return (subscription?.addons ?? []).some( |
| 17 | (addon) => addon.briven_prod_id === 'addon_security_hipaa' |
| 18 | ) |
| 19 | } |
| 20 | |
| 21 | export const billingPartnerLabel = (billingPartner?: string) => { |
| 22 | if (!billingPartner) return billingPartner |
| 23 | |
| 24 | switch (billingPartner) { |
| 25 | case 'fly': |
| 26 | return 'Fly.io' |
| 27 | case 'aws': |
| 28 | return 'AWS' |
| 29 | case 'vercel_marketplace': |
| 30 | return 'Vercel' |
| 31 | default: |
| 32 | return billingPartner |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | type PlanChangeType = 'upgrade' | 'downgrade' | 'none' |
| 37 | |
| 38 | export const getPlanChangeType = ( |
| 39 | fromPlan: PlanId | undefined, |
| 40 | toPlan: PlanId | undefined |
| 41 | ): PlanChangeType => { |
| 42 | const planChangeTypes: Record<PlanId, Record<PlanId, PlanChangeType>> = { |
| 43 | free: { |
| 44 | free: 'none', |
| 45 | pro: 'upgrade', |
| 46 | team: 'upgrade', |
| 47 | enterprise: 'upgrade', |
| 48 | platform: 'upgrade', |
| 49 | }, |
| 50 | pro: { |
| 51 | free: 'downgrade', |
| 52 | pro: 'none', |
| 53 | team: 'upgrade', |
| 54 | enterprise: 'upgrade', |
| 55 | platform: 'upgrade', |
| 56 | }, |
| 57 | team: { |
| 58 | free: 'downgrade', |
| 59 | pro: 'downgrade', |
| 60 | team: 'none', |
| 61 | enterprise: 'upgrade', |
| 62 | platform: 'upgrade', |
| 63 | }, |
| 64 | enterprise: { |
| 65 | free: 'downgrade', |
| 66 | pro: 'downgrade', |
| 67 | team: 'downgrade', |
| 68 | enterprise: 'none', |
| 69 | platform: 'upgrade', |
| 70 | }, |
| 71 | platform: { |
| 72 | free: 'downgrade', |
| 73 | pro: 'downgrade', |
| 74 | team: 'downgrade', |
| 75 | enterprise: 'downgrade', |
| 76 | platform: 'none', |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | if (!fromPlan || !toPlan) { |
| 81 | return 'none' |
| 82 | } |
| 83 | |
| 84 | return planChangeTypes[fromPlan]?.[toPlan] ?? 'none' |
| 85 | } |