Skip to content

Commit cfc99d7

Browse files
authored
chore: add BillingManagedBy constant (supabase#37919)
chore/managed-by
1 parent 7f50ee9 commit cfc99d7

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

apps/studio/components/ui/PartnerManagedResource.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { ExternalLink } from 'lucide-react'
33
import { useVercelRedirectQuery } from 'data/integrations/vercel-redirect-query'
44
import { Alert_Shadcn_, AlertTitle_Shadcn_, Button } from 'ui'
55
import PartnerIcon from './PartnerIcon'
6+
import { MANAGED_BY, ManagedBy } from 'lib/constants/infrastructure'
67

78
interface PartnerManagedResourceProps {
8-
partner: 'vercel-marketplace' | 'aws-marketplace'
9+
partner: ManagedBy
910
resource: string
1011
cta?: {
1112
installationId?: string
@@ -15,22 +16,26 @@ interface PartnerManagedResourceProps {
1516
}
1617

1718
export const PARTNER_TO_NAME = {
18-
'vercel-marketplace': 'Vercel Marketplace',
19-
'aws-marketplace': 'AWS Marketplace',
19+
[MANAGED_BY.VERCEL_MARKETPLACE]: 'Vercel Marketplace',
20+
[MANAGED_BY.AWS_MARKETPLACE]: 'AWS Marketplace',
21+
[MANAGED_BY.SUPABASE]: 'Supabase',
2022
} as const
2123

2224
function PartnerManagedResource({ partner, resource, cta }: PartnerManagedResourceProps) {
25+
const isManagedBySupabase = partner === MANAGED_BY.SUPABASE
2326
const ctaEnabled = cta !== undefined
2427

2528
const { data, isLoading, isError } = useVercelRedirectQuery(
2629
{
2730
installationId: cta?.installationId,
2831
},
2932
{
30-
enabled: ctaEnabled,
33+
enabled: ctaEnabled && !isManagedBySupabase,
3134
}
3235
)
3336

37+
if (isManagedBySupabase) return null
38+
3439
const ctaUrl = (data?.url ?? '') + (cta?.path ?? '')
3540

3641
return (

apps/studio/data/organizations/organizations-query.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,33 @@ import { get, handleError } from 'data/fetchers'
55
import { useProfile } from 'lib/profile'
66
import type { Organization, ResponseError } from 'types'
77
import { organizationKeys } from './keys'
8+
import { MANAGED_BY, ManagedBy } from 'lib/constants/infrastructure'
89

910
export type OrganizationBase = components['schemas']['OrganizationResponse']
1011

1112
export function castOrganizationResponseToOrganization(org: OrganizationBase): Organization {
1213
return {
1314
...org,
1415
billing_email: org.billing_email ?? 'Unknown',
15-
managed_by: org.slug.startsWith('vercel_icfg_') ? 'vercel-marketplace' : 'supabase',
16+
managed_by: getManagedBy(org),
1617
partner_id: org.slug.startsWith('vercel_') ? org.slug.replace('vercel_', '') : undefined,
1718
}
1819
}
1920

21+
function getManagedBy(org: OrganizationBase): ManagedBy {
22+
switch (org.billing_partner) {
23+
case 'vercel_marketplace':
24+
return MANAGED_BY.VERCEL_MARKETPLACE
25+
// TODO(ignacio): Uncomment this when we've deployed the AWS Marketplace new slug
26+
// case 'aws_marketplace':
27+
// return MANAGED_BY.AWS_MARKETPLACE
28+
case 'aws':
29+
return MANAGED_BY.AWS_MARKETPLACE
30+
default:
31+
return MANAGED_BY.SUPABASE
32+
}
33+
}
34+
2035
export async function getOrganizations({
2136
signal,
2237
headers,

apps/studio/lib/constants/infrastructure.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export const AWS_REGIONS_DEFAULT =
1111
// TO DO, change default to US region for prod
1212
export const FLY_REGIONS_DEFAULT = FLY_REGIONS.SOUTHEAST_ASIA
1313

14+
export const MANAGED_BY = {
15+
VERCEL_MARKETPLACE: 'vercel-marketplace',
16+
AWS_MARKETPLACE: 'aws-marketplace',
17+
SUPABASE: 'supabase',
18+
}
19+
20+
export type ManagedBy = (typeof MANAGED_BY)[keyof typeof MANAGED_BY]
21+
1422
export const PRICING_TIER_LABELS_ORG = {
1523
FREE: 'Free - $0/month',
1624
PRO: 'Pro - $25/month',

apps/studio/types/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
22
import { OrganizationBase } from 'data/organizations/organizations-query'
33
import { PlanId } from 'data/subscriptions/types'
44
import jsonLogic from 'json-logic-js'
5+
import { ManagedBy } from 'lib/constants/infrastructure'
56

67
export interface Organization extends OrganizationBase {
7-
managed_by: 'supabase' | 'vercel-marketplace' | 'aws-marketplace'
8+
managed_by: ManagedBy
89
partner_id?: string
910
plan: { id: PlanId; name: string }
1011
}

0 commit comments

Comments
 (0)