ProjectCreation.utils.ts 1.6 KB

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