import { SagaIterator } from 'redux-saga'; import type { FetchCtx, FetchJsonCtx, Next } from './types'; /** * Automatically sets `content-type` to `application/json` when * that header is not already present. */ export declare function headersMdw(ctx: CurCtx, next: Next): SagaIterator; /** * This middleware takes the `ctx.response` and sets `ctx.json` to the body representation * requested. It uses the `ctx.bodyType` property to determine how to represent the body. * The default is set to `json` which calls `Response.json()`. * * @example * ```ts * const fetchUsers = api.get('/users', function*(ctx, next) { * ctx.bodyType = 'text'; // calls Response.text(); * yield next(); * }) * ``` */ export declare function jsonMdw(ctx: CurCtx, next: Next): SagaIterator; export declare function apiUrlMdw(baseUrl?: string): (ctx: CurCtx, next: Next) => SagaIterator; /** * If there's a slug inside the ctx.name (which is the URL segement in this case) * and there is *not* a corresponding truthy value in the payload, then that means * the user has an empty value (e.g. empty string) which means we want to abort the * fetch request. * * e.g. `ctx.name = "/apps/:id"` with `payload = { id: '' }` * * Ideally the action wouldn't have been dispatched at all but that is *not* a * gaurantee we can make here. */ export declare function payloadMdw(ctx: CurCtx, next: Next): Generator; export declare function fetchMdw(ctx: CurCtx, next: Next): SagaIterator; /** * This middleware will retry failed `Fetch` request if `response.ok` is `false`. * It accepts a backoff function to determine how long to continue retrying. * The default is an exponential backoff {@link backoffExp} where the minimum is * 1sec between attempts and it'll reach 4s between attempts at the end with a * max of 5 attempts. * * An example backoff: * @example * ```ts * // Any value less than 0 will stop the retry middleware. * // Each attempt will wait 1s * const backoff = (attempt: number) => { * if (attempt > 5) return -1; * return 1000; * } * * const api = createApi(); * api.use(requestMonitor()); * api.use(api.routes()); * api.use(fetcher()); * * const fetchUsers = api.get('/users', [ * function*(ctx, next) { * // ... * yield next(); * }, * // fetchRetry should be after your endpoint function because * // the retry middleware will update `ctx.json` before it reaches your middleware * fetchRetry(backoff), * ]) * ``` */ export declare function fetchRetry(backoff?: (attempt: number) => number): (ctx: CurCtx, next: Next) => Generator; /** * This middleware is a composition of other middleware required to use `window.fetch` * {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API} with {@link createApi} */ export declare function fetcher({ baseUrl, }?: { baseUrl?: string; }): (context: CurCtx, next?: import("./types").Middleware> | undefined) => SagaIterator;