UNPKG

@mollie/api-client

Version:
24 lines (23 loc) 1.24 kB
import fetch, { type RequestInit, type Response, type RequestInfo } from 'node-fetch'; /** * The name of the header generated by `generateIdempotencyHeader`. */ export declare const idempotencyHeaderName = "Idempotency-Key"; export type ResponseWithIdempotencyKey = Response & { idempotencyKey: string | undefined; }; /** * Returns a wrapped version of fetch, making it attempt requests multiple times in some scenarios. * * The idea is that if the Mollie API has a brief hiccup, the extra attempts may cause the request to succeed anyway. * * If the Mollie API responds with a 5×× status code, the request will be re-attempted until: * * the Mollie API responds with a different status code, or * * the attempt limit has been reached (it gives up after the third attempt), or * * the request has timed out. * * For `POST` and `DELETE` requests, an idempotency key is added. This ensures the Mollie API can distinguish a single * request being re-attempted from two separate similarly-looking requests. In effect, this allows this client to * safely re-attempt requests. */ export declare function retryingFetch(originalFetch: typeof fetch): (url: RequestInfo, init: RequestInit) => Promise<ResponseWithIdempotencyKey>;