UNPKG

bc-webclient-mcp

Version:

Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server

117 lines 3.79 kB
/** * Retry Utilities * * Provides robust retry logic with exponential backoff, jitter, and * intelligent error classification for Business Central operations. * * Key Features: * - Exponential backoff with jitter to prevent thundering herd * - AbortSignal support for cancellation * - Intelligent error classification (retryable vs non-retryable) * - Connection boundary retry guards * - Type-safe Result<T, E> integration */ import type { Result } from './result.js'; import type { BCError } from './errors.js'; /** * Retry configuration options */ export interface RetryOptions { /** * Maximum number of retry attempts (0 = no retries, 1 = one retry after initial failure) * Default: 1 */ maxAttempts?: number; /** * Initial delay in milliseconds before first retry * Default: 1000ms (1 second) */ initialDelayMs?: number; /** * Maximum delay in milliseconds between retries (ceiling for exponential backoff) * Default: 10000ms (10 seconds) */ maxDelayMs?: number; /** * Backoff multiplier (exponential growth factor) * Default: 2 (exponential backoff: 1s, 2s, 4s, 8s, ...) */ backoffMultiplier?: number; /** * Add random jitter to prevent thundering herd * Default: true */ jitter?: boolean; /** * Optional predicate to determine if an error is retryable * If not provided, uses default isRetryableError() logic */ isRetryable?: (error: BCError) => boolean; /** * Optional AbortSignal for cancellation */ signal?: AbortSignal; /** * Optional callback invoked before each retry attempt * Receives the error that triggered the retry and the attempt number (1-based) */ onRetry?: (error: BCError, attemptNumber: number) => void; } /** * Retries an async operation with exponential backoff and intelligent error handling. * * @param fn - Async function returning Result<T, BCError> * @param options - Retry configuration * @returns Result<T, BCError> - Final result or last error * * @example * ```ts * const result = await retryWithBackoff( * () => client.connect(signal), * { maxAttempts: 2, initialDelayMs: 1000 } * ); * ``` */ export declare function retryWithBackoff<T>(fn: () => Promise<Result<T, BCError>>, options?: RetryOptions): Promise<Result<T, BCError>>; /** * Determines if an error is retryable at the connection boundary. * * Connection boundary retries are appropriate for transient network issues, * timeouts, and certain WebSocket errors that may resolve on reconnection. * * NOT retryable: * - AbortedError (external cancellation) * - AuthenticationError (credentials wrong) * - PermissionDeniedError (authorization issue) * - ValidationError (bad input data) * - SessionExpiredError (requires re-authentication, not just retry) * * Retryable: * - TimeoutError (transient) * - ConnectionError (transient) * - WebSocketConnectionError (transient) * - NetworkError (transient) * - Certain ProtocolErrors (transient) * * @param error - The error to check * @returns true if the error is retryable at connection boundary * * @example * ```ts * if (isRetryableAtConnectionBoundary(error)) { * return await retryWithBackoff(() => client.connect()); * } * ``` */ export declare function isRetryableAtConnectionBoundary(error: BCError): boolean; /** * Determines if an error is retryable (general heuristic). * * This is a more permissive check than isRetryableAtConnectionBoundary, * suitable for internal operations where retry is safe. * * @param error - The error to check * @returns true if the error is retryable */ export declare function isRetryableError(error: BCError): boolean; //# sourceMappingURL=retry.d.ts.map