From 3ac0d7309be37f5247c7e83bc2fc490fca57781d Mon Sep 17 00:00:00 2001 From: Anju <168076172+anjupathak03@users.noreply.github.com> Date: Sat, 22 Aug 2026 22:32:16 +0000 Subject: [PATCH] [AI] Migrate health-check script to TypeScript (#8599) * [AI] Migrate health-check script to TypeScript * [AI] Include TypeScript scripts in knip entries * [AI] Validate health status response type --- knip.json | 2 +- .../{health-check.js => health-check.ts} | 23 +++++++++++++++---- packages/sync-server/vite.config.mts | 2 +- .../migrate-health-check-typescript.md | 6 +++++ 4 files changed, 27 insertions(+), 6 deletions(-) rename packages/sync-server/src/scripts/{health-check.js => health-check.ts} (54%) create mode 100644 upcoming-release-notes/migrate-health-check-typescript.md diff --git a/knip.json b/knip.json index dc9fce70cd..695ed22e3b 100644 --- a/knip.json +++ b/knip.json @@ -95,7 +95,7 @@ "app.ts", "src/app.ts", "bin/**/*.js", - "src/scripts/**/*.js", + "src/scripts/**/*.{js,ts}", "src/app-*/app-*.{ts,js}" ] } diff --git a/packages/sync-server/src/scripts/health-check.js b/packages/sync-server/src/scripts/health-check.ts similarity index 54% rename from packages/sync-server/src/scripts/health-check.js rename to packages/sync-server/src/scripts/health-check.ts index 5b5a45dff0..1c208d5522 100644 --- a/packages/sync-server/src/scripts/health-check.js +++ b/packages/sync-server/src/scripts/health-check.ts @@ -5,13 +5,28 @@ const protocol = const hostname = config.get('hostname') === '::' ? 'localhost' : config.get('hostname'); +function getHealthStatus(response: unknown): string | undefined { + if ( + typeof response === 'object' && + response !== null && + 'status' in response && + typeof response.status === 'string' + ) { + return response.status; + } + + return undefined; +} + fetch(`${protocol}://${hostname}:${config.get('port')}/health`) - .then(res => res.json()) - .then(res => { - if (res.status !== 'UP') { + .then(response => response.json()) + .then(response => { + const status = getHealthStatus(response); + + if (status !== 'UP') { throw new Error( 'Health check failed: Server responded to health check with status ' + - res.status, + status, ); } }) diff --git a/packages/sync-server/vite.config.mts b/packages/sync-server/vite.config.mts index 89d2e663a2..f4e508e7b8 100644 --- a/packages/sync-server/vite.config.mts +++ b/packages/sync-server/vite.config.mts @@ -55,7 +55,7 @@ export default defineConfig({ ), 'scripts/health-check': path.resolve( __dirname, - 'src/scripts/health-check.js', + 'src/scripts/health-check.ts', ), }, output: { diff --git a/upcoming-release-notes/migrate-health-check-typescript.md b/upcoming-release-notes/migrate-health-check-typescript.md new file mode 100644 index 0000000000..a0d17e79a5 --- /dev/null +++ b/upcoming-release-notes/migrate-health-check-typescript.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [anjupathak03] +--- + +Migrate the sync-server health-check script to TypeScript