UNPKG

@settlemint/sdk-utils

Version:

Shared utilities and helper functions for SettleMint SDK modules

59 lines 2.54 kB
//#region src/http/fetch-with-retry.d.ts /** * Retry an HTTP request with exponential backoff and jitter. * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors. * * @param input - The URL or Request object to fetch * @param init - The fetch init options * @param maxRetries - Maximum number of retry attempts * @param initialSleepTime - Initial sleep time between retries in ms * @returns The fetch Response * @throws Error if all retries fail * @example * import { fetchWithRetry } from "@settlemint/sdk-utils/http"; * * const response = await fetchWithRetry("https://api.example.com/data"); */ declare function fetchWithRetry(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Response>; //#endregion //#region src/http/graphql-fetch-with-retry.d.ts /** * Executes a GraphQL request with automatic retries using exponential backoff and jitter. * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors. * Will also retry if the GraphQL response contains errors. * * @param input - The URL or Request object for the GraphQL endpoint * @param init - Optional fetch configuration options * @param maxRetries - Maximum retry attempts before failing (default: 5) * @param initialSleepTime - Initial delay between retries in milliseconds (default: 3000) * @returns The parsed GraphQL response data * @throws Error if all retries fail or if GraphQL response contains errors * @example * import { graphqlFetchWithRetry } from "@settlemint/sdk-utils/http"; * * const data = await graphqlFetchWithRetry<{ user: { id: string } }>( * "https://api.example.com/graphql", * { * method: "POST", * headers: { "Content-Type": "application/json" }, * body: JSON.stringify({ * query: `query GetUser($id: ID!) { * user(id: $id) { * id * } * }`, * variables: { id: "123" } * }) * } * ); */ declare function graphqlFetchWithRetry<Data>(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Data>; //#endregion //#region src/http/headers.d.ts type MaybeLazy<T> = T | (() => T); declare function appendHeaders(headers: MaybeLazy<HeadersInit> | undefined, additionalHeaders: Record<string, string | undefined>): [string, string][] | Headers | { [x: string]: string; }; //#endregion export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry }; //# sourceMappingURL=http.d.cts.map