@zimic/interceptor 0.16.0-canary.2 → 0.16.0-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/http.d.ts CHANGED
@@ -1,4 +1,77 @@
1
- import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
1
+ import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpBody, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
2
+
3
+ /**
4
+ * Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body
5
+ * of a request or response with the header `'content-type': 'application/json'`, if the content cannot be parsed to
6
+ * JSON.
7
+ */
8
+ declare class InvalidJSONError extends SyntaxError {
9
+ constructor(value: string);
10
+ }
11
+
12
+ /**
13
+ * Error thrown when a value is not valid {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}. HTTP
14
+ * interceptors might throw this error when trying to parse the body of a request or response with the header
15
+ * `'content-type': 'multipart/form-data'`, if the content cannot be parsed to form data.
16
+ */
17
+ declare class InvalidFormDataError extends SyntaxError {
18
+ constructor(value: string);
19
+ }
20
+
21
+ /**
22
+ * An error thrown when the interceptor is running and some operation requires it to be stopped first.
23
+ *
24
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
25
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
26
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
27
+ */
28
+ declare class RunningHttpInterceptorError extends Error {
29
+ constructor(additionalMessage: string);
30
+ }
31
+
32
+ /**
33
+ * An error thrown when the interceptor is not running and it's not possible to use the mocking utilities.
34
+ *
35
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
36
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
37
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
38
+ */
39
+ declare class NotRunningHttpInterceptorError extends Error {
40
+ constructor();
41
+ }
42
+
43
+ /**
44
+ * An error thrown when an unknown interceptor platform is detected. Currently, the platforms `node` and `browser` are
45
+ * supported.
46
+ *
47
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
48
+ */
49
+ declare class UnknownHttpInterceptorPlatformError extends Error {
50
+ constructor();
51
+ }
52
+
53
+ declare class UnknownHttpInterceptorTypeError extends TypeError {
54
+ constructor(unknownType: unknown);
55
+ }
56
+
57
+ /**
58
+ * An error thrown when the browser mock service worker is not found.
59
+ *
60
+ * @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐browser#zimic-browser-init `zimic-interceptor browser init` API reference}
61
+ */
62
+ declare class UnregisteredBrowserServiceWorkerError extends Error {
63
+ constructor();
64
+ static matchesRawError(error: unknown): boolean;
65
+ }
66
+
67
+ /**
68
+ * Error thrown when trying to access requests when the interceptor is not configured to do so.
69
+ *
70
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
71
+ */
72
+ declare class DisabledRequestSavingError extends TypeError {
73
+ constructor();
74
+ }
2
75
 
3
76
  type Default<Type, IfEmpty = never> = [undefined | void] extends [Type] ? IfEmpty : Exclude<Type, undefined | void>;
4
77
  type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
@@ -78,6 +151,97 @@ interface InterceptedHttpInterceptorRequest<Path extends string, MethodSchema ex
78
151
  response: StatusCode extends [never] ? never : HttpInterceptorResponse<MethodSchema, StatusCode>;
79
152
  }
80
153
 
154
+ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
155
+ /**
156
+ * A static headers restriction to match intercepted requests.
157
+ *
158
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
159
+ */
160
+ type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
161
+ type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
162
+ /**
163
+ * A static search params restriction to match intercepted requests.
164
+ *
165
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
166
+ */
167
+ type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
168
+ type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
169
+ /**
170
+ * A static body restriction to match intercepted requests.
171
+ *
172
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
173
+ */
174
+ type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
175
+ /**
176
+ * A static restriction to match intercepted requests.
177
+ *
178
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
179
+ */
180
+ interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
181
+ /**
182
+ * A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
183
+ * must contain exactly these headers and no others.
184
+ */
185
+ headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
186
+ /**
187
+ * A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
188
+ * request must contain exactly these search params and no others.
189
+ */
190
+ searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
191
+ /**
192
+ * The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
193
+ * contain exactly this body and no other.
194
+ */
195
+ body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
196
+ /**
197
+ * If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
198
+ * Otherwise, the request must contain **at least** them.
199
+ */
200
+ exact?: boolean;
201
+ }
202
+ /**
203
+ * A computed restriction to match intercepted requests.
204
+ *
205
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
206
+ */
207
+ type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
208
+ /**
209
+ * A restriction to match intercepted requests.
210
+ *
211
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
212
+ */
213
+ type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
214
+ interface RestrictionDiff<Value> {
215
+ expected: Value;
216
+ received: Value;
217
+ }
218
+ interface RestrictionDiffs {
219
+ computed?: RestrictionDiff<boolean>;
220
+ headers?: RestrictionDiff<HttpHeaders<never>>;
221
+ searchParams?: RestrictionDiff<HttpSearchParams<never>>;
222
+ body?: RestrictionDiff<unknown>;
223
+ }
224
+ interface UnmatchedHttpInterceptorRequestGroup {
225
+ request: HttpInterceptorRequest<string, never>;
226
+ diff: RestrictionDiffs;
227
+ }
228
+
229
+ declare class TimesDeclarationPointer extends Error {
230
+ constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
231
+ }
232
+
233
+ interface TimesCheckErrorOptions {
234
+ requestLimits: Range<number>;
235
+ numberOfMatchedRequests: number;
236
+ declarationPointer: TimesDeclarationPointer | undefined;
237
+ unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
238
+ hasRestrictions: boolean;
239
+ hasSavedRequests: boolean;
240
+ }
241
+ declare class TimesCheckError extends TypeError {
242
+ constructor(options: TimesCheckErrorOptions);
243
+ }
244
+
81
245
  type UnhandledHttpInterceptorRequestMethodSchema = HttpSchema.Method<{
82
246
  request: {
83
247
  headers: Record<string, string>;
@@ -240,85 +404,10 @@ interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions {
240
404
  * The options to create an
241
405
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor HTTP interceptor}.
242
406
  *
243
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
407
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `createHttpInterceptor(options)` API reference}
244
408
  */
245
409
  type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions;
246
410
 
247
- type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
248
- /**
249
- * A static headers restriction to match intercepted requests.
250
- *
251
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
252
- */
253
- type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
254
- type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
255
- /**
256
- * A static search params restriction to match intercepted requests.
257
- *
258
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
259
- */
260
- type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
261
- type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
262
- /**
263
- * A static body restriction to match intercepted requests.
264
- *
265
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
266
- */
267
- type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
268
- /**
269
- * A static restriction to match intercepted requests.
270
- *
271
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
272
- */
273
- interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
274
- /**
275
- * A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
276
- * must contain exactly these headers and no others.
277
- */
278
- headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
279
- /**
280
- * A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
281
- * request must contain exactly these search params and no others.
282
- */
283
- searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
284
- /**
285
- * The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
286
- * contain exactly this body and no other.
287
- */
288
- body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
289
- /**
290
- * If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
291
- * Otherwise, the request must contain **at least** them.
292
- */
293
- exact?: boolean;
294
- }
295
- /**
296
- * A computed restriction to match intercepted requests.
297
- *
298
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
299
- */
300
- type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
301
- /**
302
- * A restriction to match intercepted requests.
303
- *
304
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
305
- */
306
- type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
307
- interface RestrictionDiff<Value> {
308
- expected: Value;
309
- received: Value;
310
- }
311
- interface RestrictionDiffs {
312
- computed?: RestrictionDiff<boolean>;
313
- headers?: RestrictionDiff<HttpHeaders<never>>;
314
- searchParams?: RestrictionDiff<HttpSearchParams<never>>;
315
- body?: RestrictionDiff<unknown>;
316
- }
317
- interface UnmatchedHttpInterceptorRequestGroup {
318
- request: HttpInterceptorRequest<string, never>;
319
- diff: RestrictionDiffs;
320
- }
321
-
322
411
  /**
323
412
  * An HTTP request handler to declare responses for intercepted requests.
324
413
  *
@@ -423,7 +512,7 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
423
512
  * that was not satisfied.
424
513
  *
425
514
  * When
426
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `saveRequests: true`}
515
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
427
516
  * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
428
517
  * expected and received data. This is useful for debugging requests that did not match a handler with
429
518
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
@@ -538,7 +627,7 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
538
627
  * that was not satisfied.
539
628
  *
540
629
  * When
541
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `saveRequests: true`}
630
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
542
631
  * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
543
632
  * expected and received data. This is useful for debugging requests that did not match a handler with
544
633
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
@@ -695,7 +784,7 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
695
784
  * of each test.
696
785
  *
697
786
  * When
698
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `saveRequests: true`}
787
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
699
788
  * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
700
789
  * expected and received data. This is useful for debugging requests that did not match a handler with
701
790
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
@@ -1152,134 +1241,14 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
1152
1241
  clear: () => Promise<void>;
1153
1242
  }
1154
1243
 
1155
- /**
1156
- * Creates an HTTP interceptor.
1157
- *
1158
- * @param options The options for the interceptor.
1159
- * @returns The created HTTP interceptor.
1160
- * @throws {InvalidURLError} If the base URL is invalid.
1161
- * @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
1162
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
1163
- */
1164
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<Schema>;
1165
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
1166
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
1167
-
1168
- /**
1169
- * A namespace of interceptor resources for mocking HTTP requests.
1170
- *
1171
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
1172
- */
1173
- declare class HttpInterceptorNamespace {
1174
- /**
1175
- * Creates an HTTP interceptor.
1176
- *
1177
- * @param options The options for the interceptor.
1178
- * @returns The created HTTP interceptor.
1179
- * @throws {InvalidURLError} If the base URL is invalid.
1180
- * @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
1181
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
1182
- */
1183
- create: typeof createHttpInterceptor;
1184
- }
1185
-
1186
- /**
1187
- * Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body
1188
- * of a request or response with the header `'content-type': 'application/json'`, if the content cannot be parsed to
1189
- * JSON.
1190
- */
1191
- declare class InvalidJSONError extends SyntaxError {
1192
- constructor(value: string);
1193
- }
1194
-
1195
- /**
1196
- * Error thrown when a value is not valid {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}. HTTP
1197
- * interceptors might throw this error when trying to parse the body of a request or response with the header
1198
- * `'content-type': 'multipart/form-data'`, if the content cannot be parsed to form data.
1199
- */
1200
- declare class InvalidFormDataError extends SyntaxError {
1201
- constructor(value: string);
1202
- }
1203
-
1204
- /**
1205
- * An error thrown when the interceptor is running and some operation requires it to be stopped first.
1206
- *
1207
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
1208
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
1209
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
1210
- */
1211
- declare class RunningHttpInterceptorError extends Error {
1212
- constructor(additionalMessage: string);
1213
- }
1214
-
1215
- /**
1216
- * An error thrown when the interceptor is not running and it's not possible to use the mocking utilities.
1217
- *
1218
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
1219
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
1220
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
1221
- */
1222
- declare class NotRunningHttpInterceptorError extends Error {
1223
- constructor();
1224
- }
1225
-
1226
- /**
1227
- * An error thrown when an unknown interceptor platform is detected. Currently, the platforms `node` and `browser` are
1228
- * supported.
1229
- *
1230
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
1231
- */
1232
- declare class UnknownHttpInterceptorPlatformError extends Error {
1233
- constructor();
1234
- }
1235
-
1236
- declare class UnknownHttpInterceptorTypeError extends TypeError {
1237
- constructor(unknownType: unknown);
1238
- }
1239
-
1240
- /**
1241
- * An error thrown when the browser mock service worker is not found.
1242
- *
1243
- * @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐browser#zimic-browser-init `zimic-interceptor browser init` API reference}
1244
- */
1245
- declare class UnregisteredBrowserServiceWorkerError extends Error {
1246
- constructor();
1247
- static matchesRawError(error: unknown): boolean;
1248
- }
1249
-
1250
- /**
1251
- * Error thrown when trying to access requests when the interceptor is not configured to do so.
1252
- *
1253
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
1254
- */
1255
- declare class DisabledRequestSavingError extends TypeError {
1256
- constructor();
1257
- }
1258
-
1259
- declare class TimesDeclarationPointer extends Error {
1260
- constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
1261
- }
1262
-
1263
- interface TimesCheckErrorOptions {
1264
- requestLimits: Range<number>;
1265
- numberOfMatchedRequests: number;
1266
- declarationPointer: TimesDeclarationPointer | undefined;
1267
- unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
1268
- hasRestrictions: boolean;
1269
- hasSavedRequests: boolean;
1270
- }
1271
- declare class TimesCheckError extends TypeError {
1272
- constructor(options: TimesCheckErrorOptions);
1273
- }
1274
-
1275
1244
  /**
1276
1245
  * Infers the schema of an
1277
1246
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor`}.
1278
1247
  *
1279
1248
  * @example
1280
- * import { httpInterceptor, type InferHttpInterceptorSchema } from '@zimic/http';
1249
+ * import { type InferHttpInterceptorSchema } from '@zimic/http';
1281
1250
  *
1282
- * const interceptor = httpInterceptor.create<{
1251
+ * const interceptor = createHttpInterceptor<{
1283
1252
  * '/users': {
1284
1253
  * GET: {
1285
1254
  * response: { 200: { body: User[] } };
@@ -1304,10 +1273,16 @@ declare class TimesCheckError extends TypeError {
1304
1273
  type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInterceptor<infer Schema> ? Schema : Interceptor extends RemoteHttpInterceptor<infer Schema> ? Schema : never;
1305
1274
 
1306
1275
  /**
1307
- * A namespace of interceptor resources for mocking HTTP requests.
1276
+ * Creates an HTTP interceptor.
1308
1277
  *
1309
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
1278
+ * @param options The options for the interceptor.
1279
+ * @returns The created HTTP interceptor.
1280
+ * @throws {InvalidURLError} If the base URL is invalid.
1281
+ * @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
1282
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `createHttpInterceptor(options)` API reference}
1310
1283
  */
1311
- declare const httpInterceptor: Readonly<HttpInterceptorNamespace>;
1284
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<Schema>;
1285
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
1286
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
1312
1287
 
1313
- export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, httpInterceptor };
1288
+ 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 HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, createHttpInterceptor };