Addons.utils.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. export interface IPv4DisabledReasonOptions {
  2. isAws: boolean
  3. isProjectActive: boolean
  4. projectUpdateDisabled: boolean
  5. canUpdateIPv4: boolean
  6. ipv4Enabled: boolean
  7. }
  8. export const getIPv4DisabledReason = ({
  9. isAws,
  10. isProjectActive,
  11. projectUpdateDisabled,
  12. canUpdateIPv4,
  13. ipv4Enabled,
  14. }: IPv4DisabledReasonOptions) => {
  15. if (!isAws) {
  16. return 'Dedicated IPv4 address is only available for AWS projects'
  17. }
  18. if (!isProjectActive) {
  19. return 'Project must be active to update IPv4'
  20. }
  21. if (projectUpdateDisabled) {
  22. return 'Project updates are currently disabled'
  23. }
  24. if (!canUpdateIPv4 && !ipv4Enabled) {
  25. return 'You can only add IPv4 when your project network configuration is set to IPv6'
  26. }
  27. return undefined
  28. }
  29. export interface PitrDisabledReasonOptions {
  30. isProjectActive: boolean
  31. projectUpdateDisabled: boolean
  32. hasHipaaAddon: boolean
  33. sufficientPgVersion: boolean
  34. isOrioleDbInAws: boolean
  35. }
  36. export const getPitrDisabledReason = ({
  37. isProjectActive,
  38. projectUpdateDisabled,
  39. hasHipaaAddon,
  40. sufficientPgVersion,
  41. isOrioleDbInAws,
  42. }: PitrDisabledReasonOptions) => {
  43. if (!isProjectActive) {
  44. return 'Project must be active to update PITR'
  45. }
  46. if (projectUpdateDisabled) {
  47. return 'Project updates are currently disabled'
  48. }
  49. if (hasHipaaAddon) {
  50. return 'PITR cannot be changed with HIPAA enabled'
  51. }
  52. if (!sufficientPgVersion) {
  53. return 'Your project is too old to enable PITR'
  54. }
  55. if (isOrioleDbInAws) {
  56. return 'Point in time recovery is not supported with OrioleDB'
  57. }
  58. return undefined
  59. }
  60. export interface CustomDomainDisabledReasonOptions {
  61. isProjectActive: boolean
  62. projectUpdateDisabled: boolean
  63. }
  64. export const getCustomDomainDisabledReason = ({
  65. isProjectActive,
  66. projectUpdateDisabled,
  67. }: CustomDomainDisabledReasonOptions) => {
  68. if (!isProjectActive) {
  69. return 'Project must be active to update custom domain'
  70. }
  71. if (projectUpdateDisabled) {
  72. return 'Project updates are currently disabled'
  73. }
  74. return undefined
  75. }
  76. export type PitrAlertState = 'hipaa' | 'legacy-project' | 'orioledb' | undefined
  77. export const getPitrAlertState = ({
  78. hasHipaaAddon,
  79. sufficientPgVersion,
  80. isOrioleDbInAws,
  81. }: Pick<
  82. PitrDisabledReasonOptions,
  83. 'hasHipaaAddon' | 'sufficientPgVersion' | 'isOrioleDbInAws'
  84. >) => {
  85. if (hasHipaaAddon) {
  86. return 'hipaa'
  87. }
  88. if (!sufficientPgVersion) {
  89. return 'legacy-project'
  90. }
  91. if (isOrioleDbInAws) {
  92. return 'orioledb'
  93. }
  94. return undefined
  95. }