import Context from '../context'; import { ISerializedHttp, ISerializedRequest, ISerializedResponse } from '../http-serializer'; import { Matcher } from './matcher'; import { Redactor } from './redact'; export interface IFiltered { redact: (property: string | string[], symbol: Redactor) => void; intercepted: () => ISerializedHttp[]; mocks: () => ISerializedHttp[]; } export interface IFilteredHttpCollectionParams { context: Context; matcher?: Matcher; } export declare type PartialResponse = Partial & { statusCode: number; }; export declare type PartialResponseForRequest = PartialResponse | ((request: ISerializedRequest) => PartialResponse); /** * Represents a collection of HTTP requests which match the provided filter. * * Can filter both intercepted HTTP requests and loaded mocks. */ export default class FilteredHttpCollection implements IFiltered { private readonly ctx; private readonly matcher; constructor({ context, matcher }: IFilteredHttpCollectionParams); /** * Return all intercepted requests matching the current filter */ intercepted(): ISerializedHttp[]; /** * Return all intercepted mocks matching the current filter */ mocks(): ISerializedHttp[]; /** * Provide a mock response for all matching requests. * * Use callback to dynamically generate response per request. * * Matching responses defined here take _precedence_ over mocks loaded normally. * @param response Serialized HTTP response or callback */ respond(response: PartialResponseForRequest): void; /** * Redact given property/properties on all intercepted requests matching current filter. * * Useful whenever your HTTP requests contain sensitive details such as an API key that should not * be saved to disc. * @param property Nested path(s) for properties to redact from intercepted HTTP requests. * Works for all properties on serialized HTTP request/response objects. * Accepts dot notation for nested properties (eg `response.body.foobars[0].id`) * @param redactor Custom redactor. Defaults to replacing matching values with "*****" */ redact(property: string | string[], redactor?: Redactor): void; /** * Return serialized request part of the _single_ matching intercepted HTTP request. * * Throws an exception if multiple requests were matched. */ request(): ISerializedRequest; /** * Return serialized response part of the _single_ matching intercepted HTTP request. * * Throws an exception if multiple requests were matched. */ response(): ISerializedResponse; /** * If the current filter only matches a single request, then return the single matching instance. * Otherwise, throw an error. */ private only; }