/** * Retry Condition Helpers * Common retry condition functions for custom retry logic * * @module retry/conditions */ import type { RetryConfig, RetryResponse } from '@plyaz/types/api'; /** * Common retry condition helpers * * @example * ```typescript * import { retryConditions } from '@plyaz/api/retry'; * * const api = createApiClient({ * retry: { * attempts: 5, * shouldRetry: retryConditions.networkOnly * } * }); * ``` */ export declare const retryConditions: { /** * Retry only on network errors (no response) */ readonly networkOnly: (response: RetryResponse) => boolean; /** * Retry on timeout errors */ readonly timeoutOnly: (response: RetryResponse) => boolean; /** * Retry on specific status codes * * @example * ```typescript * shouldRetry: retryConditions.statusCodes([500, 502, 503]) * ``` */ readonly statusCodes: (codes: number[]) => (response: RetryResponse) => boolean; /** * Retry with exponential backoff based on attempt * * @example * ```typescript * shouldRetry: retryConditions.withBackoff(5) * ``` */ readonly withBackoff: (maxAttempts: number) => (_response: RetryResponse, attempt: number) => boolean; /** * Retry based on custom header presence * * @example * ```typescript * shouldRetry: retryConditions.withHeader('x-retry-allowed', 'true') * ``` */ readonly withHeader: (headerName: string, headerValue?: string) => (response: RetryResponse) => boolean; /** * Retry if response contains specific error code * * @example * ```typescript * shouldRetry: retryConditions.errorCode(['NETWORK_ERROR', 'TIMEOUT']) * ``` */ readonly errorCode: (codes: string[]) => (response: RetryResponse) => boolean; /** * Combine multiple conditions (AND) * All conditions must be true to retry * * @example * ```typescript * shouldRetry: retryConditions.all( * retryConditions.networkOnly, * retryConditions.withBackoff(3) * ) * ``` */ readonly all: (...conditions: Array<(response: RetryResponse, attempt: number) => boolean>) => (response: RetryResponse, attempt: number) => boolean; /** * Combine multiple conditions (OR) * Any condition being true will trigger retry * * @example * ```typescript * shouldRetry: retryConditions.any( * retryConditions.networkOnly, * retryConditions.timeoutOnly, * retryConditions.statusCodes([500, 502, 503]) * ) * ``` */ readonly any: (...conditions: Array<(response: RetryResponse, attempt: number) => boolean>) => (response: RetryResponse, attempt: number) => boolean; /** * Retry based on rate limit headers * Respects X-RateLimit-Remaining and Retry-After headers */ readonly rateLimit: (response: RetryResponse, attempt: number) => boolean; /** * Retry on server errors (5xx status codes) */ readonly serverErrors: (response: RetryResponse) => boolean; /** * Retry on client errors that might be transient (408, 429) */ readonly transientErrors: (response: RetryResponse) => boolean; }; /** * Create custom retry configuration with condition * * @example * ```typescript * const customRetry = createRetryConfig({ * attempts: 5, * delay: 2000, * shouldRetry: retryConditions.serverErrors * }); * ``` */ export declare function createRetryConfig(options: Partial): RetryConfig; /** * Wrap a RetryResponse condition to accept unknown * This allows our conditions to work with fetchff's unknown type */ export declare function wrapCondition(condition: (response: RetryResponse, attempt: number) => boolean): (response: unknown, attempt: number) => boolean; /** * Create a retry condition that limits retries per status code * * @example * ```typescript * shouldRetry: createStatusCodeLimits({ * 500: 5, // Retry 500 errors up to 5 times * 503: 3, // Retry 503 errors up to 3 times * 429: 10 // Retry rate limits up to 10 times * }) * ``` */ export declare function createStatusCodeLimits(limits: Record): (response: RetryResponse, attempt: number) => boolean; //# sourceMappingURL=conditions.d.ts.map