/** * Healthcheck Service * * Code-first API for defining and managing healthchecks. */ import { IHealthcheckDefineOptions, IHealthcheckSchema, IHealthcheckStatus, IHealthcheckRunResult, IDefinedHealthcheck, IResilienceServiceConfig } from './types'; /** * Error class for healthcheck operations */ export declare class HealthcheckError extends Error { code: string; details?: unknown; constructor(message: string, code: string, details?: unknown); } /** * Healthcheck Service * * Provides code-first API for defining, creating, and managing healthchecks. */ export declare class HealthcheckService { private apiService; private config; private _privateKey; private _accessKey; private productBuilders; private readonly productEnv; constructor(config: IResilienceServiceConfig & { private_key: string; access_key: string; }); private resolvePE; /** Get or create a ProductBuilder for the product (resolves tag to product id for components API) */ private createNewProductBuilder; private getOrCreateProductBuilder; private bootstrapHealthcheckForRun; private getProductBuilder; /** * Creates a ProcessorService instance for local execution */ private createProcessor; /** * Define a healthcheck using code-first API * * @example * ```ts * const healthcheck = await healthcheckService.define({ * product: 'my-product', * tag: 'stripe-health', * name: 'Stripe API Health', * handler: async (ctx) => { * ctx.probe().app('stripe-app').action('health'); * ctx.interval(30000); * ctx.retries(2); * ctx.env('prd'); * ctx.env('stg'); * }, * }); * ``` */ define(options: IHealthcheckDefineOptions): Promise; private register; /** * Create a healthcheck from a defined healthcheck or schema. * Persists as product component so processor healthcheck workers and health.list/fetch see it. */ create(product: string, healthcheck: IDefinedHealthcheck | IHealthcheckSchema): Promise; /** * Update an existing healthcheck */ update(product: string, tag: string, healthcheck: Partial | Partial): Promise; /** * Fetch a healthcheck by tag (uses product components API) */ fetch(product: string, tag: string): Promise; /** * Fetch all healthchecks for a product (uses product components API) */ fetchAll(product: string): Promise; /** * Delete a healthcheck */ delete(product: string, tag: string): Promise; /** * Get the current status of a healthcheck */ getStatus(options: { product: string; env: string; tag: string; }): Promise; private normalizeStatus; statusAll(options: { product: string; env: string; tags: string[]; }): Promise>; preflight(): Promise<{ operational: boolean; redis: boolean; scheduling: boolean; workers: boolean; statusStorage: boolean; code?: string; }>; /** * Alias for getStatus - check the health of a service * * @example * ```ts * const status = await resilience.healthcheck.check({ * product: 'my-product', * env: 'prd', * tag: 'stripe-health', * }); * console.log(status.status); // 'healthy' | 'unhealthy' | 'degraded' * ``` */ check(options: { product: string; env: string; tag: string; }): Promise; /** * Manually trigger a healthcheck * * Executes the healthcheck locally using the ProcessorService and caches * the result in Redis for status tracking. On failure, triggers configured * notifications, webhooks, and event emissions. * * Supports the following probe types: * - APP: Executes an app action (supports OAuth auto-refresh) * - DATABASE: Tests database connection * - GRAPH: Tests graph database connection * - MESSAGE_BROKER: Tests message broker connection * - STORAGE: Tests object storage connection * - FEATURE: Executes a feature and checks completion status */ run(options: { product: string; env: string; tag: string; }): Promise; /** * Handles failure notifications for a healthcheck */ private handleFailureNotifications; /** * Execute a database healthcheck probe by testing the connection */ private executeDatabaseProbe; /** * Execute a graph healthcheck probe by testing the connection */ private executeGraphProbe; /** * Execute a message broker healthcheck probe by testing the connection */ private executeMessageBrokerProbe; /** * Execute a feature healthcheck probe by running the feature * * Feature healthchecks execute the feature with the provided input * and check if it completes successfully. This is useful for testing * end-to-end feature functionality. */ private executeFeatureProbe; /** * Execute a storage healthcheck probe by testing the connection * * Storage healthchecks attempt to list objects (with limit 1) to verify * connectivity and credentials are working correctly. */ private executeStorageProbe; /** * @deprecated Use run() instead */ runNow(options: { product: string; env: string; tag: string; }): Promise; } export default HealthcheckService;