# healthcheck — Agent usage Configure a coding agent for @nexload-sdk/healthcheck. **Topic:** agents **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/agents/ ## Install matching skills Install the skills whose triggers match the task. ### healthcheck-core [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/core/SKILL.md) ```text Use when integrating or changing the runtime-neutral @nexload-sdk/healthcheck manager, scopes, profiles, aggregation, serialization, built-in checks, collectors, retries, timeouts, shutdown lifecycle, or report contracts. Do not use for framework route wiring, exporter formatting, or one custom check in isolation. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-core ``` ### healthcheck-custom-checks [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/custom-checks/SKILL.md) ```text Use when implementing or reviewing an individual custom @nexload-sdk/healthcheck check or metric collector, including check-versus-collector choice, AbortSignal propagation, scope criticality, raw metrics, stable errors, timeout and retry safety, side effects, and focused tests. Do not use for manager-only setup or a shipped adapter. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-custom-checks ``` ### healthcheck-diagnostics-security [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/diagnostics-security/SKILL.md) ```text Use when deciding or reviewing public versus private health exposure, diagnostics details, metrics access, JSON redaction, error and stack suppression, bearer or Basic authentication, IPv4/CIDR allowlists, trusted proxy headers, no-store policy, or sensitive and high-cardinality health data. Compose with the route or exporter skill that owns implementation. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-diagnostics-security ``` ## Project AGENTS.md ```markdown For @nexload-sdk/healthcheck, load healthcheck-core when its trigger matches. Read the package bundle and check public exports against the installed version before editing. ``` ## Package context [Scoped Markdown bundle](/nexload-sdk/packages/healthcheck/core/llms.txt). ## Prompts ```text Decide when a shop can accept traffic. Use @nexload-sdk/healthcheck and healthcheck-core. Inspect the installed version and show a minimal typed example for my project. ``` ```text Review my @nexload-sdk/healthcheck integration against the optimization page. Identify the relevant source for each finding and one test for the highest-risk behavior. ``` --- # API Reference & Compatibility Complete public API symbol reference, types, and runtime compatibility matrix for Healthcheck Core. **Topic:** api **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/api/ The complete public API symbol inventory is generated automatically from package source exports: ## Functions ### `aggregateStatus` ```ts aggregateStatus(results: readonly HealthCheckResult[]) => HealthStatus ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/aggregate.ts#L18) ### `autoRuntimeAdapter` ```ts autoRuntimeAdapter() => RuntimeAdapter ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/runtime.ts#L113) ### `createAbortSignal` ```ts createAbortSignal(timeoutMs: number | undefined, parent?: AbortSignal) => { signal: AbortSignal; dispose: () => void; } ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/timeout.ts#L1) ### `createHealthManager` ```ts createHealthManager(options: HealthManagerOptions) => HealthManager ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/manager.ts#L95) ### `defineHealthCheck` ```ts defineHealthCheck(definition: HealthCheckDefinition) => HealthCheckDefinition ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/define.ts#L6) ### `defineMetricCollector` ```ts defineMetricCollector(definition: MetricCollectorDefinition) => MetricCollectorDefinition ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/define.ts#L10) ### `genericRuntimeAdapter` ```ts genericRuntimeAdapter() => RuntimeAdapter ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/runtime.ts#L101) ### `httpCheck` ```ts httpCheck(name: string, url: string | URL, options?: HttpCheckOptions) => HealthCheckDefinition ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/http-check.ts#L31) ### `memoryCheck` ```ts memoryCheck(options?: { scopes?: readonly HealthScope[]; availableRatio?: { degraded: number; unhealthy: number; }; usedRatio?: { degraded: number; unhealthy: number; }; critical?: boolean | Partial>; }) => HealthCheckDefinition<"memory"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/checks.ts#L127) ### `runtimeInfoCheck` ```ts runtimeInfoCheck(options?: { scopes?: readonly HealthScope[]; critical?: boolean; }) => HealthCheckDefinition<"runtime.info"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/checks.ts#L31) ### `runtimeMetricsCollector` ```ts runtimeMetricsCollector(options?: { scopes?: readonly HealthScope[]; }) => MetricCollectorDefinition<"runtime.metrics"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/collectors.ts#L9) ### `shutdownCheck` ```ts shutdownCheck(options?: { scopes?: readonly HealthScope[]; }) => HealthCheckDefinition<"shutdown"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/checks.ts#L51) ### `sleep` ```ts sleep(ms: number, signal?: AbortSignal) => Promise ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/timeout.ts#L42) ### `startupCheck` ```ts startupCheck(options: { isStarted: () => boolean | Promise; scopes?: readonly HealthScope[]; timeoutMs?: number; }) => HealthCheckDefinition<"startup"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/checks.ts#L71) ### `statusToHttpStatus` ```ts statusToHttpStatus(status: HealthStatus, policy?: HealthHttpStatusPolicy) => number ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/http.ts#L18) ### `stringifyHealthJson` ```ts stringifyHealthJson(report: HealthReport, options?: HealthJsonOptions) => string ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/serializers.ts#L124) ### `summarizeChecks` ```ts summarizeChecks(results: readonly HealthCheckResult[]) => HealthSummary ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/aggregate.ts#L7) ### `timerLagCheck` ```ts timerLagCheck(options?: { scopes?: readonly HealthScope[]; sampleMs?: number; thresholds?: { degradedMs: number; unhealthyMs: number; }; critical?: boolean; }) => HealthCheckDefinition<"timer.lag"> ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/checks.ts#L92) ### `toHealthJson` ```ts toHealthJson(report: HealthReport, options?: HealthJsonOptions) => HealthReport ``` **Exported from:** `@nexload-sdk/healthcheck` Public function exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/serializers.ts#L89) ## Constants ### `DEFAULT_HTTP_STATUS_POLICY` ```ts DEFAULT_HTTP_STATUS_POLICY: HealthHttpStatusPolicy ``` **Exported from:** `@nexload-sdk/healthcheck` Public constant exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/http.ts#L6) ### `HEALTH_ERROR_CODES` ```ts HEALTH_ERROR_CODES: { readonly CHECK_THROWN: "CHECK_THROWN"; readonly CHECK_TIMEOUT: "CHECK_TIMEOUT"; readonly CHECK_ABORTED: "CHECK_ABORTED"; readonly HEALTHCHECK_TIMEOUT: "HEALTHCHECK_TIMEOUT"; readonly HEALTHCHECK_ABORTED: "HEALTHCHECK_ABORTED"; readonly HEALTHCHECK_DEPENDENCY_UNAVAILABLE: "HEALTHCHECK_DEPENDENCY_UNAVAILABLE"; readonly HEALTHCHECK_CONTAINER_LIMIT_UNAVAILABLE: "HEALTHCHECK_CONTAINER_LIMIT_UNAVAILABLE"; readonly HEALTHCHECK_ROUTE_UNAUTHORIZED: "HEALTHCHECK_ROUTE_UNAUTHORIZED"; readonly HEALTHCHECK_INVALID_CONFIG: "HEALTHCHECK_INVALID_CONFIG"; readonly HTTP_STATUS_MISMATCH: "HTTP_STATUS_MISMATCH"; readonly HTTP_BODY_MISMATCH: "HTTP_BODY_MISMATCH"; readonly TCP_CONNECT_FAILED: "TCP_CONNECT_FAILED"; readonly DNS_RESOLVE_FAILED: "DNS_RESOLVE_FAILED"; readonly DATABASE_PING_FAILED: "DATABASE_PING_FAILED"; readonly PAYLOAD_QUERY_FAILED: "PAYLOAD_QUERY_FAILED"; readonly RUNTIME_UNSUPPORTED: "RUNTIME_UNSUPPORTED"; readonly METRIC_UNAVAILABLE: "METRIC_UNAVAILABLE"; } ``` **Exported from:** `@nexload-sdk/healthcheck` Public constant exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/errors.ts#L1) ### `STRICT_READINESS_HTTP_STATUS_POLICY` ```ts STRICT_READINESS_HTTP_STATUS_POLICY: HealthHttpStatusPolicy ``` **Exported from:** `@nexload-sdk/healthcheck` Public constant exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/http.ts#L12) ## Interfaces ### `EnvironmentIdentity` ```ts interface EnvironmentIdentity { name?: string region?: string zone?: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L31) ### `HealthCheckDefinition` ```ts interface HealthCheckDefinition { kind?: "check" name: TName component?: string scopes: readonly HealthScope[] critical?: boolean | Partial> timeoutMs?: number retries?: RetryPolicy tags?: readonly string[] run(context: HealthRunContext): Promise | HealthCheckRunResult } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L181) ### `HealthCheckResult` ```ts interface HealthCheckResult { name: TName component?: string scope: HealthRunScope status: HealthStatus critical: boolean observedAt: string durationMs: number timedOut: boolean attempt: number metrics: HealthMetrics details?: HealthDetails error?: HealthErrorInfo tags?: readonly string[] } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L101) ### `HealthCheckRunResult` ```ts interface HealthCheckRunResult { status: HealthStatus metrics?: HealthMetrics details?: HealthDetails error?: HealthErrorInfo } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L174) ### `HealthErrorInfo` ```ts interface HealthErrorInfo { code: string message: string causeName?: string causeMessage?: string stack?: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L76) ### `HealthHttpStatusPolicy` ```ts interface HealthHttpStatusPolicy { ok: number degraded: number unhealthy: number } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L246) ### `HealthJsonOptions` ```ts interface HealthJsonOptions { includeDetails?: boolean redact?: boolean redaction?: Partial } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/serializers.ts#L83) ### `HealthLinks` ```ts interface HealthLinks { self?: string metrics?: string diagnostics?: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L126) ### `HealthManager` ```ts interface HealthManager { register(check: HealthCheckDefinition): HealthManager registerCollector(collector: MetricCollectorDefinition): HealthManager unregister(name: string): boolean run(scope: HealthRunScope, options?: HealthRunOptions): Promise setShutdownState(state: boolean, reason?: string): void isShuttingDown(): boolean dispose(): void } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L236) ### `HealthManagerOptions` ```ts interface HealthManagerOptions { service: ServiceIdentity runtime?: RuntimeAdapter | "auto" environment?: EnvironmentIdentity defaults?: { timeoutMs?: number concurrency?: number /** Defaults to true. Set false to report timed-out checks as degraded. */ unhealthyOnTimeout?: boolean includeStack?: boolean profile?: HealthDataProfile } /** Profiles are passed to checks and collectors as context hints. */ profiles?: Partial> & { default?: HealthDataProfile } /** @deprecated Configure redaction when calling toHealthJson or stringifyHealthJson. */ redaction?: Partial checks?: readonly HealthCheckDefinition[] collectors?: readonly MetricCollectorDefinition[] } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L207) ### `HealthMetric` ```ts interface HealthMetric { name: string value: HealthMetricValue unit?: | "bytes" | "seconds" | "milliseconds" | "ratio" | "count" | "percent" | "state" type?: "gauge" | "counter" | "histogram" | "info" labels?: Record description?: string observedAt?: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L84) ### `HealthReport` ```ts interface HealthReport { schemaVersion: "2.0" service: ServiceIdentity scope: HealthRunScope status: HealthStatus observedAt: string durationMs: number runtime: RuntimeIdentity environment?: EnvironmentIdentity summary: HealthSummary checks: readonly HealthCheckResult[] metrics: readonly HealthMetric[] resources?: Record links?: HealthLinks } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L132) ### `HealthRunContext` ```ts interface HealthRunContext { scope: HealthRunScope signal: AbortSignal runtime: RuntimeAdapter service: ServiceIdentity profile: HealthDataProfile now: () => number getShutdownState: () => { shuttingDown: boolean, reason?: string } result: (result: HealthCheckRunResult) => HealthCheckRunResult } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L163) ### `HealthRunOptions` ```ts interface HealthRunOptions { signal?: AbortSignal profile?: HealthDataProfile /** @deprecated Select a profile and configure serializer detail options instead. */ includeDiagnostics?: boolean includeStacks?: boolean timeoutMs?: number } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L227) ### `HealthSummary` ```ts interface HealthSummary { ok: number degraded: number unhealthy: number total: number criticalFailed: number nonCriticalFailed: number } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L117) ### `HttpCheckOptions` ```ts interface HttpCheckOptions { scopes?: readonly HealthScope[] method?: "GET" | "HEAD" | "POST" headers?: HeadersInit body?: BodyInit | null expectedStatus?: number | readonly number[] | { min: number, max: number } validateBody?: (body: string, response: Response) => boolean | Promise timeoutMs?: number } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/http-check.ts#L10) ### `MetricCollectionResult` ```ts interface MetricCollectionResult { metrics: readonly HealthMetric[] resources?: Record } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L193) ### `MetricCollectorDefinition` ```ts interface MetricCollectorDefinition { kind?: "collector" name: TName scopes?: readonly HealthScope[] defaultEnabled?: boolean timeoutMs?: number collect(context: HealthRunContext): Promise | MetricCollectionResult } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L198) ### `RedactionPolicy` ```ts interface RedactionPolicy { redactSecrets: boolean redactUrls: "none" | "query" | "origin" | "full" includeStack: boolean includeErrorMessage: boolean allowedDetailKeys?: readonly string[] } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L155) ### `RetryPolicy` ```ts interface RetryPolicy { attempts: number delayMs?: number backoff?: "none" | "linear" | "exponential" retryOn?: readonly HealthStatus[] } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L148) ### `RuntimeAdapter` ```ts interface RuntimeAdapter { name: RuntimeIdentity["name"] now(): number uptimeSeconds(): number | null getRuntimeInfo(): RuntimeIdentity getMemory?(): RuntimeMemorySnapshot | Promise getCpu?(previous?: RuntimeCpuSnapshot): RuntimeCpuSnapshot | Promise onShutdown?(signals: readonly string[], callback: (signal: string) => void): () => void } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L66) ### `RuntimeCpuSnapshot` ```ts interface RuntimeCpuSnapshot { userMicros: number | null systemMicros: number | null availableParallelism: number | null } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L60) ### `RuntimeIdentity` ```ts interface RuntimeIdentity { name: "node" | "bun" | "unknown" version?: string revision?: string platform?: string arch?: string pid?: number } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L37) ### `RuntimeMemorySnapshot` ```ts interface RuntimeMemorySnapshot { rssBytes: number | null heapTotalBytes: number | null heapUsedBytes: number | null externalBytes: number | null arrayBuffersBytes: number | null constrainedBytes: number | null availableBytes: number | null totalBytes: number | null usedRatio: number | null availableRatio: number | null source: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L46) ### `ServiceIdentity` ```ts interface ServiceIdentity { name: string version?: string environment?: string instanceId?: string } ``` **Exported from:** `@nexload-sdk/healthcheck` Public interface exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L24) ## Types ### `HealthDataProfile` ```ts type HealthDataProfile = | "probe" | "summary" | "monitoring" | "diagnostics" | "full"; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L11) ### `HealthDetails` ```ts type HealthDetails = Record; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L22) ### `HealthErrorCode` ```ts type HealthErrorCode = (typeof HEALTH_ERROR_CODES)[keyof typeof HEALTH_ERROR_CODES]; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/errors.ts#L21) ### `HealthMetricValue` ```ts type HealthMetricValue = string | number | boolean | null; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L18) ### `HealthMetrics` ```ts type HealthMetrics = Record; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L20) ### `HealthRunScope` ```ts type HealthRunScope = HealthScope | "all"; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L9) ### `HealthScope` ```ts type HealthScope = | "liveness" | "readiness" | "startup" | "diagnostics"; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L3) ### `HealthStatus` ```ts type HealthStatus = "ok" | "degraded" | "unhealthy"; ``` **Exported from:** `@nexload-sdk/healthcheck` Public type exported by @nexload-sdk/healthcheck. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/core/types.ts#L1) *** ## Runtime Compatibility Matrix | Runtime / Engine | Version Requirement | Verification Status | |---|---|---| | **Node.js** | `>=20.9.0` | Verified on Node 20 & 22 | | **Bun** | `>=1.0.0` | Verified on Bun 1.1+ | | **Edge Runtimes** | V8 / Cloudflare Workers | Core orchestration is edge-safe | | **Module Format** | ESM only | Native ECMAScript Modules | | **Side Effects** | `false` | Fully tree-shakeable | --- # Production Guides & Recipes Authoring custom checks, configuring timeouts and retries, status aggregation rules, and troubleshooting. **Topic:** guides **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/guides/ ## Authoring Custom Checks A check implements a simple async contract returning an object with `status` and optional `data`: ```ts import type { HealthCheckDefinition } from "@nexload-sdk/healthcheck"; export function postgresCheck(dbPool: any): HealthCheckDefinition { return { name: "database.postgres", scopes: ["readiness", "diagnostics"], // Excluded from liveness! critical: true, // Failure marks service unhealthy timeoutMs: 3000, // Abort after 3 seconds run: async () => { const client = await dbPool.connect(); try { await client.query("SELECT 1"); return { status: "ok" }; } finally { client.release(); } }, }; } ``` *** ## Status Aggregation Model The health manager aggregates results across all executed checks according to strict operational hierarchy: 1. **`unhealthy`**: If ANY critical check fails (`status: "unhealthy"` or unhandled error). 2. **`degraded`**: If all critical checks pass, but one or more non-critical checks return `"degraded"` or `"unhealthy"`. 3. **`ok`**: When all executed checks pass with `"ok"`. ```ts const report = await health.run("readiness"); // Kubernetes readiness HTTP response pattern: const httpStatus = report.status === "ok" ? 200 : report.status === "degraded" ? 200 : 503; ``` *** ## The Liveness Cascade Anti-Pattern > \[!CAUTION] > **Never Put External Dependencies into Liveness Probes!** > If your database has an outage and your Postgres check is part of `liveness`, Kubernetes will kill and restart every single application container simultaneously. This creates a massive thundering herd that prevents the database from ever recovering. > > * Put database, cache, and third-party checks in **`readiness`**. > * Put only internal process deadlock, event-loop lag, and memory starvation checks in **`liveness`**. *** ## Troubleshooting & Common Pitfalls ### 1. Check Is Timing Out Intermittently Check timeouts use native `AbortSignal`. If your database or HTTP client does not accept an `AbortSignal`, the background query may continue running after the manager times out. Always pass `signal` to underlying network clients: ```ts run: async ({ signal }) => { return await fetch("https://internal.service/health", { signal }); } ``` ### 2. Service Restart Loop During Deployments Ensure slow cold-start operations (e.g. database migrations) are assigned to the `startup` scope and your deployment orchestrator configures a `startupProbe` with an appropriate `failureThreshold`. ### 3. Sensitive Credentials Leaking in Health Reports When returning error data from checks, `@nexload-sdk/healthcheck` automatically redacts standard authorization headers and connection strings. Do not manually format plain-text database URLs with passwords into the public `message` string. --- # Overview & Quick Start Runtime-neutral service healthcheck manager for liveness, readiness, startup, and diagnostics orchestration. **Topic:** overview **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/ **Package:** `@nexload-sdk/healthcheck` **Workspace version:** `5.0.0` Runtime-neutral health orchestration and monitoring report foundation for production services. [npm](https://www.npmjs.com/package/@nexload-sdk/healthcheck) · [Source](https://github.com/gecut/nexload-sdk/tree/main/packages/healthcheck/core) `@nexload-sdk/healthcheck` provides a runtime-neutral health orchestration engine for modern backend services. It manages checks, collectors, timeouts, cancellation, and status aggregation, returning a deterministic `HealthReport`. *** ## 10-Second Code Snippet ```ts import { createHealthManager, memoryCheck, shutdownCheck } from "@nexload-sdk/healthcheck"; export const health = createHealthManager({ service: { name: "api-service", version: "1.0.0" }, checks: [shutdownCheck(), memoryCheck()], }); // Run readiness probe for Kubernetes / Dokploy / Docker const report = await health.run("readiness"); console.log(report.status); // "ok" | "degraded" | "unhealthy" ``` *** ## What You Get * **Multi-Scope Orchestration**: Native support for `liveness`, `readiness`, `startup`, and protected `diagnostics` scopes. * **Checks vs. Collectors**: * **Check**: Can impact aggregate service status (e.g. database connectivity, Redis ping, shutdown signals). * **Collector**: Observational only; captures telemetry and measurements (e.g. CPU load, memory RSS) without triggering container restarts. * **Resilient Execution**: Enforces per-check timeouts, retry policies, and graceful degradation. * **Sensitive Data Redaction**: Automatic masking of database credentials, authorization tokens, and private hostnames in error outputs. * **Runtime Neutrality**: Pure TypeScript core with zero Node-only assumptions; runs seamlessly on Node.js, Bun, and edge runtimes. *** ## Installation & Requirements ```bash pnpm add @nexload-sdk/healthcheck ``` With alternative package managers: ```bash # npm npm install @nexload-sdk/healthcheck # bun bun add @nexload-sdk/healthcheck ``` Requires Node `>=20.9.0` or Bun `>=1.0.0`. The package is ESM-only and side-effect free. *** ## Core Concepts: The Four Scopes | Scope | Probe Question | Failure Consequence | Recommended Checks | |---|---|---|---| | **`liveness`** | Is the process deadlocked or stuck in an unrecoverable state? | Container / process restart | Memory leak thresholds, shutdown signal, event loop freeze. **Never downstream databases!** | | **`readiness`** | Can this replica accept incoming client traffic? | Temporarily removed from load balancer pool | Database availability, Redis connection, cache warm status. | | **`startup`** | Has slow initialization or schema migration finished? | Delays liveness evaluation during boot | Database migrations, asset pre-compilation. | | **`diagnostics`** | What is the detailed operational health state? | Protected behind auth token | Detailed memory breakdown, active connections, queue depth. | *** ## Quick Start: Creating a Production Manager ```ts import { createHealthManager, memoryCheck, runtimeInfoCheck, shutdownCheck, } from "@nexload-sdk/healthcheck"; export const health = createHealthManager({ service: { name: "user-service", version: process.env.APP_VERSION ?? "1.0.0", }, checks: [ shutdownCheck(), runtimeInfoCheck(), memoryCheck({ usedRatio: { degraded: 0.85, unhealthy: 0.95 }, }), ], }); // Execute readiness probe const report = await health.run("readiness"); if (report.status === "unhealthy") { process.exitCode = 1; } ``` *** ## Next Steps * Explore [Production Guides & Custom Checks](./guides/) for database checks, timeout policies, and status aggregation rules. * View the complete [API Reference & Signatures](./api/) for all exported symbols and configuration types. ## Next steps [Optimization](./optimization/) [Agent usage](./agents/) [Playground](./playground/) --- # healthcheck — Optimization Production choices for @nexload-sdk/healthcheck. **Topic:** optimization **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/optimization/ ## Reserve liveness for the process Keep database, cache and remote HTTP checks in readiness when dependency outages should stop traffic without restarting the process. ## Protect diagnostics Expose a minimal public probe. Restrict detailed reports and metrics to authorized callers. ## Bound probe execution The manager defaults to a 1,000 ms timeout per check and eight concurrent checks. Tune these limits for the dependencies being probed. ## Profiles do not filter output Profiles are hints for checks and collectors, not report filters. Use `toHealthJson()` or `stringifyHealthJson()` to control response details. ## Sources [Package guidance](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/README.md) · [Implementation](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/core/src/index.ts). · [Matching skill](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/core/SKILL.md). --- # healthcheck — Playground Inspect a local readiness report. **Topic:** playground **Package:** `@nexload-sdk/healthcheck` v5.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/core/playground/ ## Try it Type ok, degraded or unhealthy to change a critical inventory check. Switch between the report and three export formats. ## Read the result The local manager runs a readiness check. Prometheus renders metric text, OpenMetrics adds the EOF marker, and OTel returns metric records. No network service receives the output. Enter `unhealthy`. The report includes `"status": "unhealthy"`. [API reference](/nexload-sdk/packages/healthcheck/core/api/).