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