import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpFormData, HttpHeadersSchema, HttpSearchParamsSchema, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral, InvalidFormDataError as InvalidFormDataError$1, InvalidJSONError as InvalidJSONError$1 } from '@zimic/http'; /** * An error thrown when the interceptor is running and some operation requires it to be stopped first. * * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference} * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference} * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference} */ declare class RunningHttpInterceptorError extends Error { constructor(additionalMessage: string); } /** * An error thrown when the interceptor is not running and it's not possible to use the mocking utilities. * * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference} * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference} * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference} */ declare class NotRunningHttpInterceptorError extends Error { constructor(); } /** * An error thrown when an unknown interceptor platform is detected. Currently, the platforms `node` and `browser` are * supported. * * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference} */ declare class UnknownHttpInterceptorPlatformError extends Error { constructor(); } declare class UnknownHttpInterceptorTypeError extends TypeError { constructor(unknownType: unknown); } /** * Error thrown when the safe limit of saved intercepted requests is exceeded. * * @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */ declare class RequestSavingSafeLimitExceededError extends TypeError { constructor(numberOfSavedRequests: number, safeLimit: number); } /** * An error thrown when the browser mock service worker is not found. * * @see {@link https://zimic.dev/docs/interceptor/cli/browser#zimic-interceptor-browser-init `zimic-interceptor browser init` API reference} */ declare class UnregisteredBrowserServiceWorkerError extends Error { constructor(); static matchesRawError(error: unknown): boolean; } /** * Error thrown when trying to access requests when the interceptor is not configured to do so. * * @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */ declare class DisabledRequestSavingError extends TypeError { constructor(); } type JSON = { [key: string]: JSON; } | JSON[] | string | number | boolean | null | undefined; declare namespace JSON { type Loose = Record | Loose[] | string | number | boolean | null | undefined; } /** * Represents or validates a type that is compatible with JSON. * * **IMPORTANT**: the input of `JSONValue` and all of its internal types must be declared inline or as a type aliases * (`type`). They cannot be interfaces. * * @example * import { type JSONValue } from '@zimic/http'; * * // Can be used as a standalone type: * const value: JSONValue = { * name: 'example', * tags: ['one', 'two'], * }; * * @example * import { type JSONValue } from '@zimic/http'; * * // Can be used with a type argument to validate a JSON value: * type ValidJSON = JSONValue<{ * id: string; * email: string; * createdAt: string; * }>; * * // This results in a type error: * type InvalidJSON = JSONValue<{ * id: string; * email: string; * createdAt: Date; // `Date` is not a valid JSON value. * save: () => Promise; // Functions are not valid JSON values. * }>; */ type JSONValue = Type; declare namespace JSONValue { /** A loose version of the JSON value type. JSON objects are not strictly typed. */ type Loose = Type; } /** * Recursively converts a type to its JSON-serialized version. Dates are converted to strings and keys with non-JSON * values are excluded. * * @example * import { type JSONSerialized } from '@zimic/http'; * * type SerializedUser = JSONSerialized<{ * id: string; * email: string; * createdAt: Date; * save: () => Promise; * }>; * // { * // id: string; * // email: string; * // createdAt: string; * // } */ type JSONSerialized = Type extends JSONValue ? Type : Type extends Date ? string : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map ? Record : Type extends Set ? Record : Type extends (infer ArrayItem)[] ? JSONSerialized[] : Type extends object ? { [Key in keyof Type as [JSONSerialized] extends [never] ? never : Key]: JSONSerialized; } : never; declare global { interface JSON { readonly value: unique symbol; stringify(value: Value, replacer?: ((this: any, key: string, value: Value) => any) | (number | string)[] | null, space?: string | number): JSONStringified; parse(text: JSONStringified, reviver?: (this: any, key: string, value: any) => any): JSONSerialized; } } type JSONStringified = string & { [JSON.value]: JSONSerialized; }; type Default = [undefined | void] extends [Type] ? IfEmpty : Exclude; type IfNever = [Type] extends [never] ? Yes : No; type PossiblePromise = Type | PromiseLike; type Replace = Type extends Source ? Target : Type; type PartialByKey = Omit & Partial>; type DeepPartial = Type extends (...parameters: never[]) => unknown ? Type : Type extends (infer ArrayItem)[] ? DeepPartial[] : Type extends object ? { [Key in keyof Type]?: DeepPartial; } : Type; interface Range { min: Type; max: Type; } type HttpRequestHandlerResponseBody = HttpResponseBodySchema<{ response: { [Code in StatusCode]: ResponseSchema; }; }, StatusCode>; type HttpRequestHandlerResponseWithBody = unknown extends ResponseSchema['body'] ? { body?: null; } : undefined extends ResponseSchema['body'] ? { body?: HttpRequestHandlerResponseBody; } : { body: HttpRequestHandlerResponseBody; }; type HttpRequestHandlerResponseDeclarationHeaders = HttpHeadersInit, 'content-type'>>; type HttpRequestHandlerResponseDeclarationWithHeaders = undefined extends ResponseSchema['headers'] ? { headers?: HttpRequestHandlerResponseDeclarationHeaders; } : Exclude extends 'content-type' ? { headers?: HttpRequestHandlerResponseDeclarationHeaders; } : { headers: HttpRequestHandlerResponseDeclarationHeaders; }; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ type HttpRequestHandlerStatusResponseDeclaration = StatusCode extends StatusCode ? { status: StatusCode; action?: never; } & HttpRequestHandlerResponseWithBody[StatusCode]>, StatusCode> & HttpRequestHandlerResponseDeclarationWithHeaders[StatusCode]>> : never; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ interface HttpRequestHandlerActionResponseDeclaration { status?: never; action: UnhandledRequestStrategy.Action; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ type HttpRequestHandlerResponseDeclaration = HttpRequestHandlerStatusResponseDeclaration | HttpRequestHandlerActionResponseDeclaration; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ type HttpRequestHandlerResponseDeclarationFactory = (request: Omit, 'response'>) => PossiblePromise>; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerdelay `handler.delay()` API reference} */ type HttpRequestHandlerResponseDelayFactory = (request: Omit, 'response'>) => PossiblePromise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */ interface HttpInterceptorRequest extends Omit { /** * The headers of the request. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/headers#using-request-headers Using request headers} */ headers: HttpHeaders>>; /** * The path parameters of the request. They are parsed from the path string when using dynamic paths. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/path-params#using-request-path-params Using request path parameters} */ pathParams: InferPathParams; /** * The search parameters of the request. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/search-params#using-request-search-params Using request search parameters} */ searchParams: HttpSearchParams>>; /** * The body of the request. It is already parsed by default as detailed in * {@link https://zimic.dev/docs/interceptor/guides/http/bodies#default-body-parsing Default body parsing}. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/bodies#using-request-bodies Using request bodies} */ body: Replace, ArrayBuffer | ReadableStream, Blob>; /** The raw request object. */ raw: HttpRequest, Default>>; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */ interface HttpInterceptorResponse extends Omit { /** * The headers of the response. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/headers#using-response-headers Using response headers} */ headers: HttpHeaders>>; /** The status code of the response. */ status: StatusCode; /** * The body of the response. It is already parsed by default as detailed in * {@link https://zimic.dev/docs/interceptor/guides/http/bodies#default-body-parsing Default body parsing}. * * @see {@link https://zimic.dev/docs/interceptor/guides/http/bodies#using-response-bodies Using response bodies} */ body: Replace, ArrayBuffer | ReadableStream, Blob>; /** The raw response object. */ raw: HttpResponse, Default>, StatusCode>; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */ interface InterceptedHttpInterceptorRequest extends HttpInterceptorRequest { /** The response that was returned for the intercepted request. */ response: StatusCode extends [never] ? never : HttpInterceptorResponse; } type UnhandledHttpInterceptorRequestMethodSchema = HttpSchema.Method<{ request: { headers: Record; searchParams: Record; body: HttpBody; }; }>; type UnhandledHttpInterceptorRequest = Omit, 'response'>; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptortype `interceptor.type` API reference} */ type HttpInterceptorType = 'local' | 'remote'; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference} */ type HttpInterceptorPlatform = 'node' | 'browser'; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ declare namespace UnhandledRequestStrategy { /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type LocalAction = 'bypass' | 'reject'; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type RemoteAction = 'reject'; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type Action = LocalAction | RemoteAction; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ interface Declaration { /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ action: DeclarationAction; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ log?: boolean; } /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type DeclarationFactory = (request: UnhandledHttpInterceptorRequest) => PossiblePromise>; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type LocalDeclaration = Declaration; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type LocalDeclarationFactory = DeclarationFactory; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type RemoteDeclaration = Declaration; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type RemoteDeclarationFactory = DeclarationFactory; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type Local = LocalDeclaration | LocalDeclarationFactory; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ type Remote = RemoteDeclaration | RemoteDeclarationFactory; } type UnhandledRequestStrategy = UnhandledRequestStrategy.Local | UnhandledRequestStrategy.Remote; interface SharedHttpInterceptorOptions { /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ type?: HttpInterceptorType; /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ baseURL: string; /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ requestSaving?: Partial; } /** * @see {@link https://zimic.dev/docs/interceptor/guides/http/local-interceptors#creating-a-local-http-interceptor Creating a local HTTP interceptor} * @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ interface LocalHttpInterceptorOptions extends SharedHttpInterceptorOptions { type?: 'local'; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ onUnhandledRequest?: UnhandledRequestStrategy.Local; } interface HttpInterceptorAuthOptions { /** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */ token: string; } /** * @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#creating-a-remote-http-interceptor Creating a remote HTTP interceptor} * @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions { type: 'remote'; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */ auth?: HttpInterceptorAuthOptions; /** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */ onUnhandledRequest?: UnhandledRequestStrategy.Remote; } /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions; type PartialHttpHeadersOrSchema = IfNever | HttpHeaders> | HttpHeaders>; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ type HttpRequestHandlerHeadersStaticRestriction, Path extends HttpSchemaPath> = PartialHttpHeadersOrSchema>>>; type PartialHttpSearchParamsOrSchema = IfNever | HttpSearchParams> | HttpSearchParams>; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ type HttpRequestHandlerSearchParamsStaticRestriction, Path extends HttpSchemaPath> = PartialHttpSearchParamsOrSchema>>>; type PartialBodyOrSchema = Body extends HttpFormData ? HttpFormData> | HttpFormData : Body extends HttpSearchParams ? HttpSearchParams> | HttpSearchParams : Body extends Blob ? Body : Body extends ArrayBuffer ? Body : Body extends ReadableStream ? Body : DeepPartial; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ type HttpRequestHandlerBodyStaticRestriction, Path extends HttpSchemaPath> = PartialBodyOrSchema>>; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ interface HttpRequestHandlerStaticRestriction, Path extends HttpSchemaPath> { /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ headers?: HttpRequestHandlerHeadersStaticRestriction; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ searchParams?: HttpRequestHandlerSearchParamsStaticRestriction; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ body?: HttpRequestHandlerBodyStaticRestriction; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ exact?: boolean; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ type HttpRequestHandlerComputedRestriction, Path extends HttpSchemaPath> = (request: HttpInterceptorRequest>) => PossiblePromise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ type HttpRequestHandlerRestriction, Path extends HttpSchemaPath> = HttpRequestHandlerStaticRestriction | HttpRequestHandlerComputedRestriction; interface RestrictionDiff { expected: Value; received: Value; } interface RestrictionDiffs { computed?: RestrictionDiff; headers?: RestrictionDiff; searchParams?: RestrictionDiff; body?: RestrictionDiff; } interface UnmatchedHttpInterceptorRequestGroup { request: HttpInterceptorRequest; diff: RestrictionDiffs; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */ interface HttpRequestHandler, Path extends HttpSchemaPath> { /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlermethod `handler.method` API reference} */ get method(): Method; /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerpath `handler.path` API reference} */ get path(): Path; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */ interface LocalHttpRequestHandler, Path extends HttpSchemaPath, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler { /** @readonly */ get type(): 'local'; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ with: (restriction: HttpRequestHandlerRestriction) => this; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerdelay `handler.delay()` API reference} */ delay: ((milliseconds: number | HttpRequestHandlerResponseDelayFactory>) => this) & ((minMilliseconds: number, maxMilliseconds: number) => this); /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ respond: ['response']>>>(declaration: HttpRequestHandlerResponseDeclaration, NewStatusCode> | HttpRequestHandlerResponseDeclarationFactory, NewStatusCode>) => LocalHttpRequestHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference} */ times: ((numberOfRequests: number) => this) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => this); /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference} */ checkTimes: () => void; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference} */ clear: () => this; /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */ get requests(): readonly InterceptedHttpInterceptorRequest, StatusCode>[]; } /** * A synced remote HTTP request handler. When a remote handler is synced, it is guaranteed that all of the mocking * operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. * * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */ interface SyncedRemoteHttpRequestHandler, Path extends HttpSchemaPath, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler { /** @readonly */ get type(): 'remote'; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwith `handler.with()` API reference} */ with: (restriction: HttpRequestHandlerRestriction) => PendingRemoteHttpRequestHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerdelay `handler.delay()` API reference} */ delay: ((milliseconds: number | HttpRequestHandlerResponseDelayFactory>) => PendingRemoteHttpRequestHandler) & ((minMilliseconds: number, maxMilliseconds: number) => PendingRemoteHttpRequestHandler); /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */ respond: ['response']>>>(declaration: HttpRequestHandlerResponseDeclaration, NewStatusCode> | HttpRequestHandlerResponseDeclarationFactory, NewStatusCode>) => PendingRemoteHttpRequestHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference} */ times: ((numberOfRequests: number) => PendingRemoteHttpRequestHandler) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => PendingRemoteHttpRequestHandler); /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference} */ checkTimes: () => Promise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference} */ clear: () => PendingRemoteHttpRequestHandler; /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */ get requests(): readonly InterceptedHttpInterceptorRequest, StatusCode>[]; } /** * A pending remote HTTP request handler. When a remote handler is pending, it is not guaranteed that all of the mocking * operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. * * To commit a remote interceptor, you can `await` it or use the methods {@link then handler.then()}, * {@link catch handler.catch()}, and {@link finally handler.finally()}. * * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */ interface PendingRemoteHttpRequestHandler, Path extends HttpSchemaPath, StatusCode extends HttpStatusCode = never> extends SyncedRemoteHttpRequestHandler { /** * Waits for the remote handler to be synced with the connected * {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. */ then: , RejectedResult = never>(onFulfilled?: ((handler: SyncedRemoteHttpRequestHandler) => PossiblePromise) | null, onRejected?: ((reason: unknown) => PossiblePromise) | null) => Promise; /** * Waits for the remote handler to be synced with the connected * {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. */ catch: (onRejected?: ((reason: unknown) => PossiblePromise) | null) => Promise | RejectedResult>; /** * Waits for the remote handler to be synced with the connected * {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. */ finally: (onFinally?: (() => void) | null) => Promise>; } /** * A remote HTTP request handler to declare responses for intercepted requests. In a remote handler, the mocking * operations are asynchronous and include remote calls to the connected * {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}. * * @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */ type RemoteHttpRequestHandler, Path extends HttpSchemaPath, StatusCode extends HttpStatusCode = never> = PendingRemoteHttpRequestHandler; type SyncHttpInterceptorMethodHandler = Method extends HttpSchemaMethod ? >(path: Path) => LocalHttpRequestHandler> : (path: never) => LocalHttpRequestHandler; type AsyncHttpInterceptorMethodHandler = Method extends HttpSchemaMethod ? >(path: Path) => RemoteHttpRequestHandler> : (path: never) => RemoteHttpRequestHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */ interface HttpInterceptorRequestSaving { /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */ enabled: boolean; /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */ safeLimit: number; } /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference} */ interface HttpInterceptor<_Schema extends HttpSchema> { /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorbaseurl `interceptor.baseURL` API reference} */ baseURL: string; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorrequestsaving `interceptor.requestSaving` API reference} */ requestSaving: HttpInterceptorRequestSaving; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoronunhandledrequest `interceptor.onUnhandledRequest` API reference} */ onUnhandledRequest?: UnhandledRequestStrategy; /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference} */ get platform(): HttpInterceptorPlatform | null; /** * @readonly * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference} */ get isRunning(): boolean; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference} */ start: () => Promise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference} */ stop: () => Promise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()` API reference} */ checkTimes: () => PossiblePromise; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()` API reference} */ clear: () => PossiblePromise; } /** * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference} * @see {@link https://zimic.dev/docs/interceptor/guides/http/local-interceptors Using local interceptors} */ interface LocalHttpInterceptor extends HttpInterceptor { /** @readonly */ get type(): 'local'; onUnhandledRequest?: UnhandledRequestStrategy.Local; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorget `interceptor.get()` API reference} */ get: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpost `interceptor.post()` API reference} */ post: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpatch `interceptor.patch()` API reference} */ patch: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorput `interceptor.put()` API reference} */ put: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptordelete `interceptor.delete()` API reference} */ delete: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorhead `interceptor.head()` API reference} */ head: SyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoroptions `interceptor.options()` API reference} */ options: SyncHttpInterceptorMethodHandler; checkTimes: () => void; clear: () => void; } /** * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference} * @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors Using remote interceptors} */ interface RemoteHttpInterceptor extends HttpInterceptor { /** @readonly */ get type(): 'remote'; onUnhandledRequest?: UnhandledRequestStrategy.Remote; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorauth `interceptor.auth` API reference} */ auth?: RemoteHttpInterceptorOptions['auth']; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorget `interceptor.get()` API reference} */ get: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpost `interceptor.post()` API reference} */ post: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpatch `interceptor.patch()` API reference} */ patch: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorput `interceptor.put()` API reference} */ put: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptordelete `interceptor.delete()` API reference} */ delete: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorhead `interceptor.head()` API reference} */ head: AsyncHttpInterceptorMethodHandler; /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoroptions `interceptor.options()` API reference} */ options: AsyncHttpInterceptorMethodHandler; checkTimes: () => Promise; clear: () => Promise; } declare class HttpTimesDeclarationPointer extends Error { constructor(minNumberOfRequests: number, maxNumberOfRequests?: number); } interface HttpTimesCheckErrorOptions { requestLimits: Range; numberOfMatchedRequests: number; declarationPointer: HttpTimesDeclarationPointer | undefined; unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[]; hasRestrictions: boolean; requestSaving: HttpInterceptorRequestSaving; } /** * Error thrown when the number of requests matched by a handler does not satisfy its `handler.times()` declaration. * * @deprecated `TimesCheckError` has been renamed to `HttpTimesCheckError`. */ declare class TimesCheckError extends TypeError { constructor(options: HttpTimesCheckErrorOptions); } /** Error thrown when the number of requests matched by a handler does not satisfy its `handler.times()` declaration. */ declare class HttpTimesCheckError extends TimesCheckError { constructor(options: HttpTimesCheckErrorOptions); } /** * Infers the schema of an {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor`}. * * @example * import { type InferHttpInterceptorSchema } from '@zimic/http'; * * const interceptor = createHttpInterceptor<{ * '/users': { * GET: { * response: { 200: { body: User[] } }; * }; * }; * }>({ * baseURL: 'http://localhost:3000', * }); * * type Schema = InferHttpInterceptorSchema; * // { * // '/users': { * // GET: { * // response: { 200: { body: User[] } }; * // }; * // }; * // } * * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference} */ type InferHttpInterceptorSchema = Interceptor extends LocalHttpInterceptor ? Schema : Interceptor extends RemoteHttpInterceptor ? Schema : never; /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */ declare function createHttpInterceptor(options: LocalHttpInterceptorOptions): LocalHttpInterceptor; declare function createHttpInterceptor(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor; declare function createHttpInterceptor(options: HttpInterceptorOptions): LocalHttpInterceptor | RemoteHttpInterceptor; /** * Error thrown when a value is not valid {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}. HTTP * interceptors might throw this error when trying to parse the body of a request or response with the header * `'content-type': 'multipart/form-data'`, if the content cannot be parsed to form data. * * @deprecated This type has been moved to {@link https://zimic.dev/docs/http `@zimic/http`}. Please import * `InvalidFormDataError` from `@zimic/http` instead. * * ```ts * import { InvalidFormDataError } from '@zimic/http'; * ``` */ declare class InvalidFormDataError extends InvalidFormDataError$1 { } /** * Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body * of a request or response with the header `'content-type': 'application/json'`, if the content cannot be parsed to * JSON. * * @deprecated This type has been moved to {@link https://zimic.dev/docs/http `@zimic/http`}. Please import * `InvalidJSONError` from `@zimic/http` instead. * * ```ts * import { InvalidJSONError } from '@zimic/http'; * ``` */ declare class InvalidJSONError extends InvalidJSONError$1 { } export { DisabledRequestSavingError, type HttpInterceptor, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerResponseDelayFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, HttpTimesCheckError, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RequestSavingSafeLimitExceededError, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, createHttpInterceptor };