ProjectCreation.utils.ts47 lines · main
1import type { CloudProvider, Region } from 'shared-data'
2import { AWS_REGIONS, FLY_REGIONS } from 'shared-data'
3import { SMART_REGION_TO_EXACT_REGION_MAP } from 'shared-data/regions'
4
5import { DesiredInstanceSize, instanceSizeSpecs } from '@/data/projects/new-project.constants'
6
7export function smartRegionToExactRegion(smartOrExactRegion: string) {
8 return SMART_REGION_TO_EXACT_REGION_MAP.get(smartOrExactRegion) ?? smartOrExactRegion
9}
10
11export function getAvailableRegions(cloudProvider: CloudProvider): Region {
12 switch (cloudProvider) {
13 case 'AWS':
14 case 'AWS_K8S':
15 return AWS_REGIONS
16 case 'AWS_NIMBUS':
17 if (process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod') {
18 // Only allow Southeast Asia for Nimbus (local/staging)
19 return {
20 SOUTHEAST_ASIA: AWS_REGIONS.SOUTHEAST_ASIA,
21 }
22 }
23
24 // Only allow US East for Nimbus (prod)
25 return {
26 EAST_US: AWS_REGIONS.EAST_US,
27 }
28 case 'FLY':
29 return FLY_REGIONS
30 default:
31 throw new Error('Invalid cloud provider')
32 }
33}
34
35/**
36 * When launching new projects, they only get assigned a compute size once successfully launched,
37 * this might assume wrong compute size, but only for projects being rapidly launched after one another on non-default compute sizes.
38 *
39 * Needs to be in the API in the future [kevin]
40 */
41export const monthlyInstancePrice = (instance: string | undefined): number => {
42 return instanceSizeSpecs[instance as DesiredInstanceSize]?.priceMonthly || 10
43}
44
45export const instanceLabel = (instance: string | undefined): string => {
46 return instanceSizeSpecs[instance as DesiredInstanceSize]?.label || 'Micro'
47}