import { IncomingMessage } from 'node:http'; import { ServerResponse } from 'node:http'; /** * @public */ declare const apimock: { /** * Configure apimock-express. */ config(mocks: MockEntry | MockEntry[] | Mock | Mock[], userConfig?: Partial): void; /** * Express/Connect middleware. * * Usage: * * ```ts * app.use("/", mockRequest); * ``` */ mockRequest(req: IncomingMessage, res: ServerResponse, next: () => void): Promise; /** * Vite plugin for apimock-express. * * @param mocks - Mock configuration * @param options - Options */ vitePlugin(mocks: MockEntry | MockEntry[] | Mock | Mock[], options?: Partial): { name: string; }; }; export default apimock; /** * A callback function for dynamically loading a mock response. * * @public * @typeParam T - The type of the response body. */ export declare type DynamicMockResponse = (req: MockRequest) => StaticMockResponse; /* Excluded from this release type: generateForBrowser */ /* Excluded from this release type: GenerateForBrowserOptions */ /** * Configuration options for the middleware. * * @public */ export declare interface MiddlewareConfiguration { /** * If enabled a summary of the configured mock will be displayed. Default is *`true`. */ verbose?: boolean; } /** * A complete mock description. * * @public * @typeParam T - The type of the response bodies. * @typeParam U - The type of the request bodies. */ export declare interface Mock { meta?: MockMeta; /** * An array of mappings between requests and corresponding mock responses. */ responses?: Array>; /** * The default response if no other match (from responses) could be found. */ defaultResponse: MockResponse; } /** * @public */ export declare interface MockEntry { /** * URL to match. Should always start with a `/`. * * If multiple entries have overlapping URLs the last matching URL takes * precedence over former matches. */ url: string; /** * Path to thte directory containing the mocks. Relative to working * directory. */ dir: string; /** * Adds a fixed delay to all mocks under this entry. */ delay?: number; } /** * Describes a mapping of a request to a specific mock response. * * @public * @typeParam T - The type of the response body. * @typeParam U - The type of the request body. */ export declare interface MockMatcher { /** * The response (value) for this mock match. */ response: MockResponse; /** * The request (key) for this mock match. */ request: MockRequest; } /** * API metadata. * * @public */ export declare interface MockMeta { /** Human readable title of this endpoint */ title?: string; /** Unique key for this endpoint, if present it should be used as the cookie * for all requests */ key?: string; /** Unique url for mock, not in use for file based mocks, example: /path/subpath */ url?: string; /** HTTP Method, not in use for file based mocks. * Valid values: GET / POST / DELETE / PUT */ method?: string; } /** * Describes a request for the mock server to listen for. * * @public * @typeParam T - The type of the request body. */ export declare interface MockRequest { /** * A key to value mapping of cookies to match. */ cookies?: Record; /** * A key to value mapping of parameters to match. */ parameters?: Record; /** * A key to value mapping of headers to match. */ headers?: Record; /** * The request body to match. */ body?: T; } /** * Describes a mock response. * * @public * @typeParam T - The type of the response body. */ export declare type MockResponse = StaticMockResponse | DynamicMockResponse; /** * Loop through the alternative responses in the mockdata. * And select the first matching response depending on the request * parameters, body, headers or cookies. * If no match could be found, then return the default response. * * @public */ export declare function selectResponse(mockdata: Mock, body: string, requestparameters: Record, bodyParameters: Record, headers: Record, cookies: Record): StaticMockResponse | undefined; /** * A description of a static mock response. * * @public * @typeParam T - The type of the response body. */ export declare interface StaticMockResponse { /** Human readable label for this mock entry. */ label?: string; /** Human readable description for this mock entry. */ description?: string; /** * Number of milliseconds of delay before responding. */ delay?: number; /** * The HTTP status code to respond with. */ status?: number; /** * A key to value mapping of HTTP headers to respond with. */ headers?: Record; /** * The response body. */ body?: T | ((req: MockRequest) => T); } /** * Vite plugin for apimock-express. * * @public * @param mocks - Mock configuration * @param options - Options */ export declare function vitePlugin(mocks: MockEntry | MockEntry[] | Mock | Mock[], options?: Partial): { name: string; }; /** * Options for Vite plugin. * * @public */ export declare interface VitePluginOptions extends MiddlewareConfiguration { /** * Enable/disable plugin. Can optionally be set to which command to enable * the plugin for. Default is `true` (enabled for all commands). */ enabled?: "serve" | "preview" | boolean; } export { }