import semver from 'semver' ; const rcVersionRegex = /^(\d+\.\d+\.\d+)\-rc(\d+)$/i ; function extractRcNumber ( version ) { const match = version . match ( rcVersionRegex ) ; return match ? [ match [ 1 ] , parseInt ( match [ 2 ] , 10 ) ] : [ version , Infinity ] ; } export function isConfigVersionUpgradeable ( savedVersion , opensearchDashboardsVersion ) { if ( typeof savedVersion !== 'string' || typeof opensearchDashboardsVersion !== 'string' || savedVersion === opensearchDashboardsVersion || /alpha|beta|snapshot/i . test ( savedVersion ) ) { return false ; } const [ savedReleaseVersion , savedRcNumber ] = extractRcNumber ( savedVersion ) ; const [ opensearchDashboardsReleaseVersion , opensearchDashboardsRcNumber ] = extractRcNumber ( opensearchDashboardsVersion ) ; if ( ! semver . valid ( savedReleaseVersion ) || ! semver . valid ( opensearchDashboardsReleaseVersion ) ) { return false ; } const savedIsLessThanOpenSearchDashboards = semver . lt ( savedReleaseVersion , opensearchDashboardsReleaseVersion ) ; const savedIsSameAsOpenSearchDashboards = semver . eq ( savedReleaseVersion , opensearchDashboardsReleaseVersion ) ; const savedRcIsLessThanOpenSearchDashboards = savedRcNumber < opensearchDashboardsRcNumber ; const savedIsFromPrefork = semver . gte ( savedReleaseVersion , '6.8.0' ) && semver . lte ( savedReleaseVersion , '7.10.2' ) ; const currentVersionIsVersion1 = semver . major ( opensearchDashboardsReleaseVersion ) === 1 ; return ( savedIsLessThanOpenSearchDashboards || ( savedIsSameAsOpenSearchDashboards && savedRcIsLessThanOpenSearchDashboards ) || ( savedIsFromPrefork && currentVersionIsVersion1 ) ) ; }