( featureName: string, requiredBuildDate: string, )
| 44 | * @returns Promise<boolean> - true if server supports the feature |
| 45 | */ |
| 46 | export async function checkServerFeatureSupport( |
| 47 | featureName: string, |
| 48 | requiredBuildDate: string, |
| 49 | ): Promise<boolean> { |
| 50 | const cacheKey = `${featureName}`; |
| 51 | |
| 52 | // Return cached result if available |
| 53 | if (featureCache.has(cacheKey)) { |
| 54 | return featureCache.get(cacheKey)!; |
| 55 | } |
| 56 | |
| 57 | let supported = false; |
| 58 | |
| 59 | try { |
| 60 | logger.debug(`[Feature Detection] Checking server support for feature: ${featureName}`); |
| 61 | |
| 62 | const versionUrl = getRemoteVersionUrl(); |
| 63 | |
| 64 | if (versionUrl) { |
| 65 | const response = await fetchWithProxy(versionUrl, { |
| 66 | method: 'GET', |
| 67 | headers: { 'Content-Type': 'application/json' }, |
| 68 | }); |
| 69 | |
| 70 | const data = await response.json(); |
| 71 | |
| 72 | if (data.buildDate) { |
| 73 | // Parse build date and check if it's after the required date |
| 74 | const buildDate = new Date(data.buildDate); |
| 75 | const featureDate = new Date(requiredBuildDate); |
| 76 | supported = buildDate >= featureDate; |
| 77 | logger.debug( |
| 78 | `[Feature Detection] ${featureName}: buildDate=${data.buildDate}, required=${requiredBuildDate}, supported=${supported}`, |
| 79 | ); |
| 80 | } else { |
| 81 | logger.debug(`[Feature Detection] ${featureName}: no version info, assuming not supported`); |
| 82 | supported = false; |
| 83 | } |
| 84 | } else { |
| 85 | logger.debug( |
| 86 | `[Feature Detection] No remote URL available for ${featureName}, assuming local server supports it`, |
| 87 | ); |
| 88 | supported = true; |
| 89 | } |
| 90 | } catch (error) { |
| 91 | logger.debug( |
| 92 | `[Feature Detection] Version check failed for ${featureName}, assuming not supported: ${error}`, |
| 93 | ); |
| 94 | supported = false; |
| 95 | } |
| 96 | |
| 97 | // Cache the result |
| 98 | featureCache.set(cacheKey, supported); |
| 99 | return supported; |
| 100 | } |
| 101 | |
| 102 | export async function checkServerRunning(port = getDefaultPort()): Promise<boolean> { |
| 103 | logger.debug(`Checking for existing server on port ${port}...`); |
no test coverage detected
searching dependent graphs…