/** * @public * Append a base path to every mock in given list. * If one of the items is missing meta field, the function will throw an Error * @param mocks - Array of mocks * @param basePath - Path to append, for example: /api */ export declare function appendBasePath(mocks: Mock[], basePath: string): Mock[]; /** * 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; /** * @public */ export declare type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; /** * Match a Fetch `Request` against provided mock array * * @param mockdata - List of mock definitions * @param request - A Fetch API `Request` * @returns A Fetch API `Response`. Will return a default 404 if no match is found * @public */ export declare function matchRequest(mockdata: Mock[], request: Request): Promise; /** * Respond the given mockdata based by url, cookie, request parameters and headers- * * Major differences between this function and matchResponse is: * This function will automagically retrieve cookies and request parameters * Function will always return in a mock-response, the fallback will be a mocked 404 request if no given mock is matched * @public */ export declare function matchResponseBrowser(options: MatchResponseBrowserInterface): MockResponse; /** * @public */ export declare interface MatchResponseBrowserInterface { mockdata: Mock[]; requestUrl: string; method: HttpMethod; body: string; bodyParameters: Record; headers: Record; } /** * 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; } /** * 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); } export { }