@zimic/interceptor 0.19.1-canary.1 → 0.19.1-canary.3
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/{chunk-6PRFBMY7.mjs → chunk-7BR57OM2.mjs} +3 -3
- package/dist/chunk-7BR57OM2.mjs.map +1 -0
- package/dist/{chunk-3NJLJSD6.js → chunk-QB2A2272.js} +3 -3
- package/dist/chunk-QB2A2272.js.map +1 -0
- package/dist/cli.js +20 -20
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +262 -467
- package/dist/http.js +5 -5
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +5 -5
- package/dist/http.mjs.map +1 -1
- package/dist/scripts/postinstall.js +1 -17
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/scripts/postinstall.mjs +2 -17
- package/dist/scripts/postinstall.mjs.map +1 -1
- package/dist/server.d.ts +14 -15
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +8 -8
- package/src/cli/server/start.ts +1 -1
- package/src/cli/server/token/create.ts +1 -1
- package/src/http/interceptor/errors/NotRunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +2 -2
- package/src/http/interceptor/errors/RunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
- package/src/http/interceptor/factory.ts +1 -9
- package/src/http/interceptor/types/options.ts +32 -132
- package/src/http/interceptor/types/public.ts +153 -236
- package/src/http/interceptor/types/schema.ts +2 -3
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +1 -1
- package/src/http/interceptorWorker/errors/UnregisteredBrowserServiceWorkerError.ts +2 -2
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +2 -2
- package/src/http/requestHandler/errors/TimesCheckError.ts +1 -1
- package/src/http/requestHandler/types/public.ts +60 -73
- package/src/http/requestHandler/types/restrictions.ts +6 -6
- package/src/server/errors/InvalidInterceptorTokenError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenFileError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenValueError.ts +1 -1
- package/src/server/errors/RunningInterceptorServerError.ts +1 -1
- package/src/server/factory.ts +3 -3
- package/src/server/types/options.ts +2 -3
- package/src/server/types/public.ts +8 -8
- package/dist/chunk-3NJLJSD6.js.map +0 -1
- package/dist/chunk-6PRFBMY7.mjs.map +0 -1
package/dist/http.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, I
|
|
|
3
3
|
/**
|
|
4
4
|
* An error thrown when the interceptor is running and some operation requires it to be stopped first.
|
|
5
5
|
*
|
|
6
|
-
* @see {@link https://
|
|
7
|
-
* @see {@link https://
|
|
8
|
-
* @see {@link https://
|
|
6
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference}
|
|
7
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference}
|
|
8
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference}
|
|
9
9
|
*/
|
|
10
10
|
declare class RunningHttpInterceptorError extends Error {
|
|
11
11
|
constructor(additionalMessage: string);
|
|
@@ -14,9 +14,9 @@ declare class RunningHttpInterceptorError extends Error {
|
|
|
14
14
|
/**
|
|
15
15
|
* An error thrown when the interceptor is not running and it's not possible to use the mocking utilities.
|
|
16
16
|
*
|
|
17
|
-
* @see {@link https://
|
|
18
|
-
* @see {@link https://
|
|
19
|
-
* @see {@link https://
|
|
17
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference}
|
|
18
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference}
|
|
19
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference}
|
|
20
20
|
*/
|
|
21
21
|
declare class NotRunningHttpInterceptorError extends Error {
|
|
22
22
|
constructor();
|
|
@@ -26,7 +26,7 @@ declare class NotRunningHttpInterceptorError extends Error {
|
|
|
26
26
|
* An error thrown when an unknown interceptor platform is detected. Currently, the platforms `node` and `browser` are
|
|
27
27
|
* supported.
|
|
28
28
|
*
|
|
29
|
-
* @see {@link https://
|
|
29
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference}
|
|
30
30
|
*/
|
|
31
31
|
declare class UnknownHttpInterceptorPlatformError extends Error {
|
|
32
32
|
constructor();
|
|
@@ -39,7 +39,7 @@ declare class UnknownHttpInterceptorTypeError extends TypeError {
|
|
|
39
39
|
/**
|
|
40
40
|
* Error thrown when the safe limit of saved intercepted requests is exceeded.
|
|
41
41
|
*
|
|
42
|
-
* @see {@link https://
|
|
42
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
|
|
43
43
|
*/
|
|
44
44
|
declare class RequestSavingSafeLimitExceededError extends TypeError {
|
|
45
45
|
constructor(numberOfSavedRequests: number, safeLimit: number);
|
|
@@ -66,7 +66,7 @@ declare class InvalidJSONError extends SyntaxError {
|
|
|
66
66
|
/**
|
|
67
67
|
* An error thrown when the browser mock service worker is not found.
|
|
68
68
|
*
|
|
69
|
-
* @see {@link https://
|
|
69
|
+
* @see {@link https://zimic.dev/docs/interceptor/cli/browser#zimic-interceptor-browser-init `zimic-interceptor browser init` API reference}
|
|
70
70
|
*/
|
|
71
71
|
declare class UnregisteredBrowserServiceWorkerError extends Error {
|
|
72
72
|
constructor();
|
|
@@ -76,7 +76,7 @@ declare class UnregisteredBrowserServiceWorkerError extends Error {
|
|
|
76
76
|
/**
|
|
77
77
|
* Error thrown when trying to access requests when the interceptor is not configured to do so.
|
|
78
78
|
*
|
|
79
|
-
* @see {@link https://
|
|
79
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
|
|
80
80
|
*/
|
|
81
81
|
declare class DisabledRequestSavingError extends TypeError {
|
|
82
82
|
constructor();
|
|
@@ -173,198 +173,97 @@ type UnhandledHttpInterceptorRequestMethodSchema = HttpSchema.Method<{
|
|
|
173
173
|
}>;
|
|
174
174
|
type UnhandledHttpInterceptorRequest = Omit<HttpInterceptorRequest<string, UnhandledHttpInterceptorRequestMethodSchema>, 'response'>;
|
|
175
175
|
|
|
176
|
-
/**
|
|
177
|
-
* An type of an HTTP interceptor.
|
|
178
|
-
*
|
|
179
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
|
|
180
|
-
*/
|
|
176
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptortype `interceptor.type` API reference} */
|
|
181
177
|
type HttpInterceptorType = 'local' | 'remote';
|
|
182
|
-
/**
|
|
183
|
-
* The platform where an HTTP interceptor is running.
|
|
184
|
-
*
|
|
185
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
186
|
-
*/
|
|
178
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference} */
|
|
187
179
|
type HttpInterceptorPlatform = 'node' | 'browser';
|
|
188
|
-
/**
|
|
189
|
-
* The strategy to treat unhandled requests.
|
|
190
|
-
*
|
|
191
|
-
* When `log` is `true` or `undefined`, warnings about unhandled requests are logged to the console. If provided a
|
|
192
|
-
* factory, unhandled request warnings will be logged if the function returns a
|
|
193
|
-
* {@link UnhandledRequestStrategy.Declaration strategy declaration} containing `log` as `true` or `undefined`.
|
|
194
|
-
*
|
|
195
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
196
|
-
*/
|
|
180
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
197
181
|
declare namespace UnhandledRequestStrategy {
|
|
198
|
-
/**
|
|
199
|
-
* The action to take when an unhandled request is intercepted.
|
|
200
|
-
*
|
|
201
|
-
* In a {@link https://github.com/zimicjs/zimic/wiki/getting‐started#local-http-interceptors local interceptor}, the
|
|
202
|
-
* action is always `bypass`, meaning that unhandled requests pass through the interceptor and reach the real network.
|
|
203
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#local-http-interceptors Remote interceptors} always use
|
|
204
|
-
* `reject`, since unhandled requests that react an
|
|
205
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server} cannot be bypassed.
|
|
206
|
-
*
|
|
207
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
208
|
-
*/
|
|
182
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
209
183
|
type Action = 'bypass' | 'reject';
|
|
210
|
-
/**
|
|
211
|
-
* A static declaration of the strategy to use for unhandled requests.
|
|
212
|
-
*
|
|
213
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
214
|
-
*/
|
|
184
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
215
185
|
interface Declaration<DeclarationAction extends Action = Action> {
|
|
216
|
-
/**
|
|
186
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
217
187
|
action: DeclarationAction;
|
|
218
|
-
/**
|
|
219
|
-
* Whether to log unhandled requests to the console.
|
|
220
|
-
*
|
|
221
|
-
* @default true
|
|
222
|
-
*/
|
|
188
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
223
189
|
log?: boolean;
|
|
224
190
|
}
|
|
225
|
-
/**
|
|
226
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request.
|
|
227
|
-
*
|
|
228
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
229
|
-
*/
|
|
191
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
230
192
|
type DeclarationFactory<DeclarationAction extends Action = Action> = (request: UnhandledHttpInterceptorRequest) => PossiblePromise<Declaration<DeclarationAction>>;
|
|
231
|
-
/**
|
|
232
|
-
* A static declaration of the strategy to use for unhandled requests in local interceptors.
|
|
233
|
-
*
|
|
234
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
235
|
-
*/
|
|
193
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
236
194
|
type LocalDeclaration = Declaration;
|
|
237
|
-
/**
|
|
238
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request in local interceptors.
|
|
239
|
-
*
|
|
240
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
241
|
-
*/
|
|
195
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
242
196
|
type LocalDeclarationFactory = DeclarationFactory;
|
|
243
|
-
/**
|
|
244
|
-
* A static declaration of the strategy to use for unhandled requests in remote interceptors.
|
|
245
|
-
*
|
|
246
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
247
|
-
*/
|
|
197
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
248
198
|
type RemoteDeclaration = Declaration<'reject'>;
|
|
249
|
-
/**
|
|
250
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request in remote interceptors.
|
|
251
|
-
*
|
|
252
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
253
|
-
*/
|
|
199
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
254
200
|
type RemoteDeclarationFactory = DeclarationFactory<'reject'>;
|
|
255
|
-
/**
|
|
201
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
256
202
|
type Local = LocalDeclaration | LocalDeclarationFactory;
|
|
257
|
-
/**
|
|
203
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
258
204
|
type Remote = RemoteDeclaration | RemoteDeclarationFactory;
|
|
259
205
|
}
|
|
260
206
|
type UnhandledRequestStrategy = UnhandledRequestStrategy.Local | UnhandledRequestStrategy.Remote;
|
|
261
207
|
interface SharedHttpInterceptorOptions {
|
|
262
|
-
/**
|
|
263
|
-
* The type of the HTTP interceptor.
|
|
264
|
-
*
|
|
265
|
-
* @default 'local'
|
|
266
|
-
*/
|
|
208
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
267
209
|
type?: HttpInterceptorType;
|
|
268
|
-
/**
|
|
269
|
-
* Represents the URL that should be matched by the interceptor. Any request starting with this base URL will be
|
|
270
|
-
* intercepted if a matching
|
|
271
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler handler} exists.
|
|
272
|
-
*
|
|
273
|
-
* For {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptors}, this
|
|
274
|
-
* base URL should point to an
|
|
275
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}. It may include
|
|
276
|
-
* additional paths to differentiate between conflicting mocks.
|
|
277
|
-
*/
|
|
210
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
278
211
|
baseURL: string;
|
|
279
|
-
/**
|
|
280
|
-
* Configures if the intercepted requests are saved and how they are handled.
|
|
281
|
-
*
|
|
282
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
283
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
284
|
-
*/
|
|
212
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
285
213
|
requestSaving?: Partial<HttpInterceptorRequestSaving>;
|
|
286
214
|
}
|
|
287
215
|
/**
|
|
288
|
-
*
|
|
289
|
-
* {@link https://
|
|
290
|
-
*
|
|
291
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#creating-a-local-http-interceptor Creating a local HTTP interceptor}
|
|
216
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/local-interceptors#creating-a-local-http-interceptor Creating a local HTTP interceptor}
|
|
217
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference}
|
|
292
218
|
*/
|
|
293
219
|
interface LocalHttpInterceptorOptions extends SharedHttpInterceptorOptions {
|
|
294
220
|
type?: 'local';
|
|
295
|
-
/**
|
|
296
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
297
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
298
|
-
* unhandled request.
|
|
299
|
-
*
|
|
300
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
301
|
-
*/
|
|
221
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
302
222
|
onUnhandledRequest?: UnhandledRequestStrategy.Local;
|
|
303
223
|
}
|
|
224
|
+
interface HttpInterceptorAuthOptions {
|
|
225
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */
|
|
226
|
+
token: string;
|
|
227
|
+
}
|
|
304
228
|
/**
|
|
305
|
-
*
|
|
306
|
-
* {@link https://
|
|
307
|
-
*
|
|
308
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#creating-a-remote-http-interceptor Creating a remote HTTP interceptor}
|
|
229
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#creating-a-remote-http-interceptor Creating a remote HTTP interceptor}
|
|
230
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference}
|
|
309
231
|
*/
|
|
310
232
|
interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions {
|
|
311
233
|
type: 'remote';
|
|
312
|
-
/**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
*
|
|
316
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#authentication Interceptor server authentication}
|
|
317
|
-
*/
|
|
318
|
-
auth?: {
|
|
319
|
-
/**
|
|
320
|
-
* The authentication token to use.
|
|
321
|
-
*
|
|
322
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#authentication Interceptor server authentication}
|
|
323
|
-
*/
|
|
324
|
-
token: string;
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
328
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
329
|
-
* unhandled request.
|
|
330
|
-
*
|
|
331
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
332
|
-
*/
|
|
234
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */
|
|
235
|
+
auth?: HttpInterceptorAuthOptions;
|
|
236
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
333
237
|
onUnhandledRequest?: UnhandledRequestStrategy.Remote;
|
|
334
238
|
}
|
|
335
|
-
/**
|
|
336
|
-
* The options to create an
|
|
337
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor HTTP interceptor}.
|
|
338
|
-
*
|
|
339
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `createHttpInterceptor(options)` API reference}
|
|
340
|
-
*/
|
|
239
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
341
240
|
type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions;
|
|
342
241
|
|
|
343
242
|
type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema.Loose> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
|
|
344
243
|
/**
|
|
345
244
|
* A static headers restriction to match intercepted requests.
|
|
346
245
|
*
|
|
347
|
-
* @see {@link https://
|
|
246
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
348
247
|
*/
|
|
349
248
|
type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>>;
|
|
350
249
|
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema.Loose> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
|
|
351
250
|
/**
|
|
352
251
|
* A static search params restriction to match intercepted requests.
|
|
353
252
|
*
|
|
354
|
-
* @see {@link https://
|
|
253
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
355
254
|
*/
|
|
356
255
|
type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<Default<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>>;
|
|
357
256
|
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>;
|
|
358
257
|
/**
|
|
359
258
|
* A static body restriction to match intercepted requests.
|
|
360
259
|
*
|
|
361
|
-
* @see {@link https://
|
|
260
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
362
261
|
*/
|
|
363
262
|
type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
364
263
|
/**
|
|
365
264
|
* A static restriction to match intercepted requests.
|
|
366
265
|
*
|
|
367
|
-
* @see {@link https://
|
|
266
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
368
267
|
*/
|
|
369
268
|
interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
370
269
|
/**
|
|
@@ -391,13 +290,13 @@ interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method
|
|
|
391
290
|
/**
|
|
392
291
|
* A computed restriction to match intercepted requests.
|
|
393
292
|
*
|
|
394
|
-
* @see {@link https://
|
|
293
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
395
294
|
*/
|
|
396
295
|
type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
|
|
397
296
|
/**
|
|
398
297
|
* A restriction to match intercepted requests.
|
|
399
298
|
*
|
|
400
|
-
* @see {@link https://
|
|
299
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
401
300
|
*/
|
|
402
301
|
type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
|
|
403
302
|
interface RestrictionDiff<Value> {
|
|
@@ -419,17 +318,17 @@ interface UnmatchedHttpInterceptorRequestGroup {
|
|
|
419
318
|
* An HTTP request handler to declare responses for intercepted requests.
|
|
420
319
|
*
|
|
421
320
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
422
|
-
* {@link https://
|
|
321
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
423
322
|
* will be used.
|
|
424
323
|
*
|
|
425
|
-
* @see {@link https://
|
|
324
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
426
325
|
*/
|
|
427
326
|
interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
428
327
|
/**
|
|
429
328
|
* The method that matches this handler.
|
|
430
329
|
*
|
|
431
330
|
* @readonly
|
|
432
|
-
* @see {@link https://
|
|
331
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlermethod `handler.method` API reference}
|
|
433
332
|
*/
|
|
434
333
|
get method(): Method;
|
|
435
334
|
/**
|
|
@@ -437,7 +336,7 @@ interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchem
|
|
|
437
336
|
* requests.
|
|
438
337
|
*
|
|
439
338
|
* @readonly
|
|
440
|
-
* @see {@link https://
|
|
339
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerpath `handler.path` API reference}
|
|
441
340
|
*/
|
|
442
341
|
get path(): Path;
|
|
443
342
|
}
|
|
@@ -446,10 +345,10 @@ interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchem
|
|
|
446
345
|
* operations are synchronous and are executed in the same process where it was created.
|
|
447
346
|
*
|
|
448
347
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
449
|
-
* {@link https://
|
|
348
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
450
349
|
* will be used.
|
|
451
350
|
*
|
|
452
|
-
* @see {@link https://
|
|
351
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
453
352
|
*/
|
|
454
353
|
interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler<Schema, Method, Path> {
|
|
455
354
|
/** @readonly */
|
|
@@ -468,7 +367,7 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
468
367
|
*
|
|
469
368
|
* @param restriction The restriction to match intercepted requests.
|
|
470
369
|
* @returns The same handler, now considering the specified restriction.
|
|
471
|
-
* @see {@link https://
|
|
370
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
472
371
|
*/
|
|
473
372
|
with: (restriction: HttpRequestHandlerRestriction<Schema, Method, Path>) => this;
|
|
474
373
|
/**
|
|
@@ -480,7 +379,7 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
480
379
|
* @param declaration The response declaration or a factory to create it.
|
|
481
380
|
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
482
381
|
* status code.
|
|
483
|
-
* @see {@link https://
|
|
382
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
484
383
|
*/
|
|
485
384
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(declaration: HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, NewStatusCode> | HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>) => LocalHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
|
|
486
385
|
/**
|
|
@@ -494,55 +393,53 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
494
393
|
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
495
394
|
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
496
395
|
* intercepted request in the
|
|
497
|
-
* {@link https://
|
|
396
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
498
397
|
*
|
|
499
398
|
* **Important**: To make sure that all expected requests were made, use
|
|
500
|
-
* {@link https://
|
|
501
|
-
*
|
|
502
|
-
* {@link https://
|
|
503
|
-
*
|
|
399
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} or
|
|
400
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
401
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} is
|
|
402
|
+
* generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
504
403
|
*
|
|
505
404
|
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
506
405
|
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
507
406
|
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
508
407
|
* @returns The same handler, now considering the specified number of times.
|
|
509
|
-
* @see {@link https://
|
|
408
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
510
409
|
*/
|
|
511
410
|
times: ((numberOfRequests: number) => this) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => this);
|
|
512
411
|
/**
|
|
513
412
|
* Checks if the handler has matched the expected number of requests declared with
|
|
514
|
-
* {@link https://
|
|
413
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
515
414
|
*
|
|
516
415
|
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
517
416
|
* pointing to the
|
|
518
|
-
* {@link https://
|
|
417
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
519
418
|
* that was not satisfied.
|
|
520
419
|
*
|
|
521
|
-
* When
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
526
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
420
|
+
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in
|
|
421
|
+
* your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
422
|
+
* received data. This is useful for debugging requests that did not match a handler with
|
|
423
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
527
424
|
*
|
|
528
425
|
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
529
|
-
* @see {@link https://
|
|
426
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
530
427
|
*/
|
|
531
428
|
checkTimes: () => void;
|
|
532
429
|
/**
|
|
533
430
|
* Clears any response declared with
|
|
534
|
-
* [`handler.respond(declaration)`](https://
|
|
431
|
+
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
535
432
|
* restrictions declared with
|
|
536
|
-
* [`handler.with(restriction)`](https://
|
|
433
|
+
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
537
434
|
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
538
435
|
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
539
436
|
* be intercepted.
|
|
540
437
|
*
|
|
541
438
|
* To make the handler match requests again, register a new response with
|
|
542
|
-
* {@link https://
|
|
439
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
543
440
|
*
|
|
544
441
|
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
545
|
-
* @see {@link https://
|
|
442
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
546
443
|
*/
|
|
547
444
|
clear: () => this;
|
|
548
445
|
/**
|
|
@@ -550,24 +447,20 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
550
447
|
* useful for testing that the correct requests were made by your application.
|
|
551
448
|
*
|
|
552
449
|
* **Important**: This method can only be used if
|
|
553
|
-
* {@link https://
|
|
554
|
-
*
|
|
555
|
-
* `true` in the interceptor. See
|
|
556
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
557
|
-
* for more information.
|
|
450
|
+
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
451
|
+
* interceptor.
|
|
558
452
|
*
|
|
559
453
|
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
560
454
|
* @readonly
|
|
561
|
-
* @see {@link https://
|
|
455
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
562
456
|
*/
|
|
563
457
|
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
564
458
|
}
|
|
565
459
|
/**
|
|
566
460
|
* A synced remote HTTP request handler. When a remote handler is synced, it is guaranteed that all of the mocking
|
|
567
|
-
* operations were committed to the connected
|
|
568
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
461
|
+
* operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
569
462
|
*
|
|
570
|
-
* @see {@link https://
|
|
463
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
571
464
|
*/
|
|
572
465
|
interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler<Schema, Method, Path> {
|
|
573
466
|
/** @readonly */
|
|
@@ -586,7 +479,7 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
586
479
|
*
|
|
587
480
|
* @param restriction The restriction to match intercepted requests.
|
|
588
481
|
* @returns The same handler, now considering the specified restriction.
|
|
589
|
-
* @see {@link https://
|
|
482
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
590
483
|
*/
|
|
591
484
|
with: (restriction: HttpRequestHandlerRestriction<Schema, Method, Path>) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
592
485
|
/**
|
|
@@ -598,7 +491,7 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
598
491
|
* @param declaration The response declaration or a factory to create it.
|
|
599
492
|
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
600
493
|
* status code.
|
|
601
|
-
* @see {@link https://
|
|
494
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
602
495
|
*/
|
|
603
496
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(declaration: HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, NewStatusCode> | HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>) => PendingRemoteHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
|
|
604
497
|
/**
|
|
@@ -612,56 +505,53 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
612
505
|
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
613
506
|
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
614
507
|
* intercepted request in the
|
|
615
|
-
* {@link https://
|
|
508
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
616
509
|
*
|
|
617
510
|
* **Important**: To make sure that all expected requests were made, use
|
|
618
|
-
* {@link https://
|
|
619
|
-
*
|
|
620
|
-
* {@link https://
|
|
621
|
-
*
|
|
622
|
-
* is generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
511
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} or
|
|
512
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()`}.
|
|
513
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} is
|
|
514
|
+
* generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
623
515
|
*
|
|
624
516
|
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
625
517
|
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
626
518
|
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
627
519
|
* @returns The same handler, now considering the specified number of times.
|
|
628
|
-
* @see {@link https://
|
|
520
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
629
521
|
*/
|
|
630
522
|
times: ((numberOfRequests: number) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>);
|
|
631
523
|
/**
|
|
632
524
|
* Checks if the handler has matched the expected number of requests declared with
|
|
633
|
-
* {@link https://
|
|
525
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
634
526
|
*
|
|
635
527
|
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
636
528
|
* pointing to the
|
|
637
|
-
* {@link https://
|
|
529
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
638
530
|
* that was not satisfied.
|
|
639
531
|
*
|
|
640
|
-
* When
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
645
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
532
|
+
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is true in your
|
|
533
|
+
* interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
534
|
+
* received data. This is useful for debugging requests that did not match a handler with
|
|
535
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
646
536
|
*
|
|
647
537
|
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
648
|
-
* @see {@link https://
|
|
538
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
649
539
|
*/
|
|
650
540
|
checkTimes: () => Promise<void>;
|
|
651
541
|
/**
|
|
652
542
|
* Clears any response declared with
|
|
653
|
-
* [`handler.respond(declaration)`](https://
|
|
543
|
+
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
654
544
|
* restrictions declared with
|
|
655
|
-
* [`handler.with(restriction)`](https://
|
|
545
|
+
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
656
546
|
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
657
547
|
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
658
548
|
* be intercepted.
|
|
659
549
|
*
|
|
660
550
|
* To make the handler match requests again, register a new response with
|
|
661
|
-
* {@link https://
|
|
551
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
662
552
|
*
|
|
663
553
|
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
664
|
-
* @see {@link https://
|
|
554
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
665
555
|
*/
|
|
666
556
|
clear: () => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
667
557
|
/**
|
|
@@ -669,130 +559,96 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
669
559
|
* useful for testing that the correct requests were made by your application.
|
|
670
560
|
*
|
|
671
561
|
* **Important**: This method can only be used if
|
|
672
|
-
* {@link https://
|
|
673
|
-
*
|
|
674
|
-
* `true` in the interceptor. See
|
|
675
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
676
|
-
* for more information.
|
|
562
|
+
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
563
|
+
* interceptor.
|
|
677
564
|
*
|
|
678
565
|
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
679
566
|
* @readonly
|
|
680
|
-
* @see {@link https://
|
|
567
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
681
568
|
*/
|
|
682
569
|
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
683
570
|
}
|
|
684
571
|
/**
|
|
685
572
|
* A pending remote HTTP request handler. When a remote handler is pending, it is not guaranteed that all of the mocking
|
|
686
|
-
* operations were committed to the connected
|
|
687
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
573
|
+
* operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
688
574
|
*
|
|
689
575
|
* To commit a remote interceptor, you can `await` it or use the methods {@link then handler.then()},
|
|
690
576
|
* {@link catch handler.catch()}, and {@link finally handler.finally()}.
|
|
691
577
|
*
|
|
692
|
-
* @see {@link https://
|
|
578
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
693
579
|
*/
|
|
694
580
|
interface PendingRemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> extends SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode> {
|
|
695
581
|
/**
|
|
696
582
|
* Waits for the remote handler to be synced with the connected
|
|
697
|
-
* {@link https://
|
|
583
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
698
584
|
*/
|
|
699
585
|
then: <FulfilledResult = SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>, RejectedResult = never>(onFulfilled?: ((handler: SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>) => PossiblePromise<FulfilledResult>) | null, onRejected?: ((reason: unknown) => PossiblePromise<RejectedResult>) | null) => Promise<FulfilledResult | RejectedResult>;
|
|
700
586
|
/**
|
|
701
587
|
* Waits for the remote handler to be synced with the connected
|
|
702
|
-
* {@link https://
|
|
588
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
703
589
|
*/
|
|
704
590
|
catch: <RejectedResult = never>(onRejected?: ((reason: unknown) => PossiblePromise<RejectedResult>) | null) => Promise<SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode> | RejectedResult>;
|
|
705
591
|
/**
|
|
706
592
|
* Waits for the remote handler to be synced with the connected
|
|
707
|
-
* {@link https://
|
|
593
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
708
594
|
*/
|
|
709
595
|
finally: (onFinally?: (() => void) | null) => Promise<SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>>;
|
|
710
596
|
}
|
|
711
597
|
/**
|
|
712
598
|
* A remote HTTP request handler to declare responses for intercepted requests. In a remote handler, the mocking
|
|
713
599
|
* operations are asynchronous and include remote calls to the connected
|
|
714
|
-
* {@link https://
|
|
600
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
715
601
|
*
|
|
716
602
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
717
|
-
* {@link https://
|
|
603
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
718
604
|
* will be used.
|
|
719
605
|
*
|
|
720
|
-
* @see {@link https://
|
|
606
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
721
607
|
*/
|
|
722
608
|
type RemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> = PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
723
609
|
|
|
724
610
|
type SyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => LocalHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => LocalHttpRequestHandler<any, any, never>;
|
|
725
611
|
type AsyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => RemoteHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => RemoteHttpRequestHandler<any, any, never>;
|
|
726
612
|
|
|
727
|
-
/**
|
|
728
|
-
* Configures if the intercepted requests are saved and how they are handled.
|
|
729
|
-
*
|
|
730
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
731
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
732
|
-
*/
|
|
613
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
733
614
|
interface HttpInterceptorRequestSaving {
|
|
734
|
-
/**
|
|
735
|
-
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
736
|
-
* should save their intercepted requests in memory and make them accessible through
|
|
737
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
738
|
-
*
|
|
739
|
-
* If you are using
|
|
740
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
741
|
-
* or
|
|
742
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerchecktimes `handler.checkTimes()`}
|
|
743
|
-
* during tests, consider enabling this option to get more detailed information in `TimesCheckError` errors.
|
|
744
|
-
*
|
|
745
|
-
* **Important**: If `requestSaving.enabled` is `true`, make sure to regularly clear the interceptor to avoid requests
|
|
746
|
-
* accumulating in memory. A common practice is to call
|
|
747
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
748
|
-
* after each test.
|
|
749
|
-
*
|
|
750
|
-
* @default process.env.NODE_ENV === 'test'
|
|
751
|
-
*/
|
|
615
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
752
616
|
enabled: boolean;
|
|
753
|
-
/**
|
|
754
|
-
* The safe number of requests to save in memory before logging warnings in the console. If `requestSaving.enabled` is
|
|
755
|
-
* `true` and the interceptor is not regularly cleared with
|
|
756
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`},
|
|
757
|
-
* the requests may accumulate in memory and cause performance issues. This option does not limit the number of
|
|
758
|
-
* requests saved in memory, only when to log warnings.
|
|
759
|
-
*
|
|
760
|
-
* @default 1000
|
|
761
|
-
*/
|
|
617
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
762
618
|
safeLimit: number;
|
|
763
619
|
}
|
|
764
620
|
/**
|
|
765
621
|
* An interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters, and
|
|
766
622
|
* responses are statically-typed based on the provided service schema.
|
|
767
623
|
*
|
|
768
|
-
* @see {@link https://
|
|
624
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
769
625
|
*/
|
|
770
626
|
interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
771
627
|
/**
|
|
772
628
|
* The base URL used by the interceptor.
|
|
773
629
|
*
|
|
774
|
-
* @see {@link https://
|
|
630
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorbaseurl `interceptor.baseURL` API reference}
|
|
775
631
|
*/
|
|
776
632
|
baseURL: string;
|
|
777
633
|
/**
|
|
778
634
|
* Configures if the intercepted requests are saved and how they are handled.
|
|
779
635
|
*
|
|
780
|
-
* @see {@link https://
|
|
781
|
-
* @see {@link https://
|
|
636
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
|
|
637
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing}
|
|
782
638
|
*/
|
|
783
639
|
requestSaving: HttpInterceptorRequestSaving;
|
|
784
640
|
/**
|
|
785
641
|
* The platform the interceptor is running on.
|
|
786
642
|
*
|
|
787
643
|
* @readonly
|
|
788
|
-
* @see {@link https://
|
|
644
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference}
|
|
789
645
|
*/
|
|
790
646
|
get platform(): HttpInterceptorPlatform | null;
|
|
791
647
|
/**
|
|
792
648
|
* Whether the interceptor is currently running and ready to use.
|
|
793
649
|
*
|
|
794
650
|
* @readonly
|
|
795
|
-
* @see {@link https://
|
|
651
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference}
|
|
796
652
|
*/
|
|
797
653
|
get isRunning(): boolean;
|
|
798
654
|
/**
|
|
@@ -803,52 +659,50 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
803
659
|
*
|
|
804
660
|
* @throws {UnregisteredServiceWorkerError} When the worker is targeting a browser environment and the mock service
|
|
805
661
|
* worker is not registered.
|
|
806
|
-
* @see {@link https://
|
|
662
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference}
|
|
807
663
|
*/
|
|
808
664
|
start: () => Promise<void>;
|
|
809
665
|
/**
|
|
810
666
|
* Stops the interceptor, preventing it from intercepting HTTP requests. Stopped interceptors are automatically
|
|
811
667
|
* cleared, exactly as if
|
|
812
|
-
* {@link https://
|
|
813
|
-
*
|
|
668
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()`} had been
|
|
669
|
+
* called.
|
|
814
670
|
*
|
|
815
|
-
* @see {@link https://
|
|
671
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference}
|
|
816
672
|
*/
|
|
817
673
|
stop: () => Promise<void>;
|
|
818
674
|
/**
|
|
819
675
|
* Checks if all handlers created by this interceptor have matched the number of requests declared with
|
|
820
|
-
* {@link https://
|
|
676
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
821
677
|
*
|
|
822
678
|
* If some handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error,
|
|
823
679
|
* including a stack trace to the
|
|
824
|
-
* {@link https://
|
|
825
|
-
*
|
|
680
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`} that was not
|
|
681
|
+
* satisfied.
|
|
826
682
|
*
|
|
827
683
|
* This is useful in an `afterEach` hook (or equivalent) to make sure that all expected requests were made at the end
|
|
828
684
|
* of each test.
|
|
829
685
|
*
|
|
830
|
-
* When
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
835
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
686
|
+
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in
|
|
687
|
+
* your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
688
|
+
* received data. This is useful for debugging requests that did not match a handler with
|
|
689
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
836
690
|
*
|
|
837
691
|
* @throws {TimesCheckError} If some handler has matched less or more requests than the expected number of requests.
|
|
838
|
-
* @see {@link https://
|
|
839
|
-
* @see {@link https://
|
|
692
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()` API reference}
|
|
693
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing guide}
|
|
840
694
|
*/
|
|
841
695
|
checkTimes: (() => void) | (() => Promise<void>);
|
|
842
696
|
/**
|
|
843
697
|
* Clears the interceptor and all of its
|
|
844
|
-
* {@link https://
|
|
845
|
-
*
|
|
846
|
-
*
|
|
698
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} instances, including their
|
|
699
|
+
* registered responses and intercepted requests. After calling this method, the interceptor will no longer intercept
|
|
700
|
+
* any requests until new mock responses are registered.
|
|
847
701
|
*
|
|
848
702
|
* This method is useful to reset the interceptor mocks between tests.
|
|
849
703
|
*
|
|
850
704
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
851
|
-
* @see {@link https://
|
|
705
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()` API reference}
|
|
852
706
|
*/
|
|
853
707
|
clear: (() => void) | (() => Promise<void>);
|
|
854
708
|
}
|
|
@@ -857,9 +711,9 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
857
711
|
* and responses are statically-typed based on the provided service schema.
|
|
858
712
|
*
|
|
859
713
|
* To intercept HTTP requests, the interceptor must have been started with
|
|
860
|
-
* {@link https://
|
|
714
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`}.
|
|
861
715
|
*
|
|
862
|
-
* @see {@link https://
|
|
716
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
863
717
|
*/
|
|
864
718
|
interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
865
719
|
/** @readonly */
|
|
@@ -869,20 +723,18 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
869
723
|
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
870
724
|
* unhandled request.
|
|
871
725
|
*
|
|
872
|
-
* @see {@link https://
|
|
726
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests}
|
|
873
727
|
*/
|
|
874
728
|
onUnhandledRequest?: UnhandledRequestStrategy.Local;
|
|
875
729
|
/**
|
|
876
|
-
* Creates a GET
|
|
877
|
-
*
|
|
878
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
730
|
+
* Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
731
|
+
* The path and method must be declared in the interceptor schema.
|
|
879
732
|
*
|
|
880
733
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
881
734
|
* interceptor, and the method, path,
|
|
882
|
-
* {@link https://
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
735
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
736
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
737
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
886
738
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
887
739
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
888
740
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -890,24 +742,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
890
742
|
*
|
|
891
743
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
892
744
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
893
|
-
* @returns A GET
|
|
894
|
-
*
|
|
895
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
745
|
+
* @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
746
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
896
747
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
897
|
-
* @see {@link https://
|
|
748
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
898
749
|
*/
|
|
899
750
|
get: SyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
900
751
|
/**
|
|
901
|
-
* Creates a POST
|
|
902
|
-
*
|
|
903
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
752
|
+
* Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
753
|
+
* The path and method must be declared in the interceptor schema.
|
|
904
754
|
*
|
|
905
755
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
906
756
|
* interceptor, and the method, path,
|
|
907
|
-
* {@link https://
|
|
908
|
-
*
|
|
909
|
-
*
|
|
910
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
757
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
758
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
759
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
911
760
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
912
761
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
913
762
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -915,24 +764,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
915
764
|
*
|
|
916
765
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
917
766
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
918
|
-
* @returns A POST
|
|
919
|
-
*
|
|
920
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
767
|
+
* @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
768
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
921
769
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
922
|
-
* @see {@link https://
|
|
770
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
923
771
|
*/
|
|
924
772
|
post: SyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
925
773
|
/**
|
|
926
|
-
* Creates a PATCH
|
|
927
|
-
*
|
|
928
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
774
|
+
* Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
775
|
+
* The path and method must be declared in the interceptor schema.
|
|
929
776
|
*
|
|
930
777
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
931
778
|
* interceptor, and the method, path,
|
|
932
|
-
* {@link https://
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
779
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
780
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
781
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
936
782
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
937
783
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
938
784
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -940,24 +786,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
940
786
|
*
|
|
941
787
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
942
788
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
943
|
-
* @returns A PATCH
|
|
944
|
-
*
|
|
945
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
789
|
+
* @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
790
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
946
791
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
947
|
-
* @see {@link https://
|
|
792
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
948
793
|
*/
|
|
949
794
|
patch: SyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
950
795
|
/**
|
|
951
|
-
* Creates a PUT
|
|
952
|
-
*
|
|
953
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
796
|
+
* Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
797
|
+
* The path and method must be declared in the interceptor schema.
|
|
954
798
|
*
|
|
955
799
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
956
800
|
* interceptor, and the method, path,
|
|
957
|
-
* {@link https://
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
801
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
802
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
803
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
961
804
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
962
805
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
963
806
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -965,24 +808,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
965
808
|
*
|
|
966
809
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
967
810
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
968
|
-
* @returns A PUT
|
|
969
|
-
*
|
|
970
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
811
|
+
* @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
812
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
971
813
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
972
|
-
* @see {@link https://
|
|
814
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
973
815
|
*/
|
|
974
816
|
put: SyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
975
817
|
/**
|
|
976
|
-
* Creates a DELETE
|
|
977
|
-
*
|
|
978
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
818
|
+
* Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
819
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
979
820
|
*
|
|
980
821
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
981
822
|
* interceptor, and the method, path,
|
|
982
|
-
* {@link https://
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
823
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
824
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
825
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
986
826
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
987
827
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
988
828
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -990,24 +830,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
990
830
|
*
|
|
991
831
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
992
832
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
993
|
-
* @returns A DELETE
|
|
994
|
-
*
|
|
995
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
833
|
+
* @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
834
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
996
835
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
997
|
-
* @see {@link https://
|
|
836
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
998
837
|
*/
|
|
999
838
|
delete: SyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
1000
839
|
/**
|
|
1001
|
-
* Creates a HEAD
|
|
1002
|
-
*
|
|
1003
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
840
|
+
* Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
841
|
+
* The path and method must be declared in the interceptor schema.
|
|
1004
842
|
*
|
|
1005
843
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1006
844
|
* interceptor, and the method, path,
|
|
1007
|
-
* {@link https://
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
845
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
846
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
847
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1011
848
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1012
849
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1013
850
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1015,24 +852,21 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
1015
852
|
*
|
|
1016
853
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1017
854
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1018
|
-
* @returns A HEAD
|
|
1019
|
-
*
|
|
1020
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
855
|
+
* @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
856
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1021
857
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1022
|
-
* @see {@link https://
|
|
858
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1023
859
|
*/
|
|
1024
860
|
head: SyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
1025
861
|
/**
|
|
1026
|
-
* Creates an OPTIONS
|
|
1027
|
-
*
|
|
1028
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
862
|
+
* Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
863
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
1029
864
|
*
|
|
1030
865
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1031
866
|
* interceptor, and the method, path,
|
|
1032
|
-
* {@link https://
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
867
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
868
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
869
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1036
870
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1037
871
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1038
872
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1040,11 +874,10 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
1040
874
|
*
|
|
1041
875
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1042
876
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1043
|
-
* @returns An OPTIONS
|
|
1044
|
-
*
|
|
1045
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
877
|
+
* @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
878
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1046
879
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1047
|
-
* @see {@link https://
|
|
880
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1048
881
|
*/
|
|
1049
882
|
options: SyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
1050
883
|
checkTimes: () => void;
|
|
@@ -1055,11 +888,10 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
1055
888
|
* and responses are statically-typed based on the provided service schema.
|
|
1056
889
|
*
|
|
1057
890
|
* To intercept HTTP requests, the interceptor must have been started with
|
|
1058
|
-
* {@link https://
|
|
1059
|
-
*
|
|
1060
|
-
* running.
|
|
891
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`} and an
|
|
892
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server} should be running.
|
|
1061
893
|
*
|
|
1062
|
-
* @see {@link https://
|
|
894
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
1063
895
|
*/
|
|
1064
896
|
interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
1065
897
|
/** @readonly */
|
|
@@ -1068,7 +900,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1068
900
|
* Options to authenticate the interceptor when connecting to an interceptor server. This is required if the
|
|
1069
901
|
* interceptor server was started with the `--tokens-dir` option.
|
|
1070
902
|
*
|
|
1071
|
-
* @see {@link https://
|
|
903
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
|
|
1072
904
|
*/
|
|
1073
905
|
auth?: RemoteHttpInterceptorOptions['auth'];
|
|
1074
906
|
/**
|
|
@@ -1076,25 +908,22 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1076
908
|
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
1077
909
|
* unhandled request.
|
|
1078
910
|
*
|
|
1079
|
-
* @see {@link https://
|
|
911
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests}
|
|
1080
912
|
*/
|
|
1081
913
|
onUnhandledRequest?: UnhandledRequestStrategy.Remote;
|
|
1082
914
|
/**
|
|
1083
|
-
* Creates a GET
|
|
1084
|
-
*
|
|
1085
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
915
|
+
* Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
916
|
+
* The path and method must be declared in the interceptor schema.
|
|
1086
917
|
*
|
|
1087
|
-
* When using a
|
|
1088
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
918
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1089
919
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1090
920
|
* apply them by awaiting the handler.
|
|
1091
921
|
*
|
|
1092
922
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1093
923
|
* interceptor, and the method, path,
|
|
1094
|
-
* {@link https://
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
924
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
925
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
926
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1098
927
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1099
928
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1100
929
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1102,29 +931,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1102
931
|
*
|
|
1103
932
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1104
933
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1105
|
-
* @returns A GET
|
|
1106
|
-
*
|
|
1107
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
934
|
+
* @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
935
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1108
936
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1109
|
-
* @see {@link https://
|
|
937
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1110
938
|
*/
|
|
1111
939
|
get: AsyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
1112
940
|
/**
|
|
1113
|
-
* Creates a POST
|
|
1114
|
-
*
|
|
1115
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
941
|
+
* Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
942
|
+
* The path and method must be declared in the interceptor schema.
|
|
1116
943
|
*
|
|
1117
|
-
* When using a
|
|
1118
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
944
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1119
945
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1120
946
|
* apply them by awaiting the handler.
|
|
1121
947
|
*
|
|
1122
948
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1123
949
|
* interceptor, and the method, path,
|
|
1124
|
-
* {@link https://
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
1127
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
950
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
951
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
952
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1128
953
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1129
954
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1130
955
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1132,29 +957,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1132
957
|
*
|
|
1133
958
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1134
959
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1135
|
-
* @returns A POST
|
|
1136
|
-
*
|
|
1137
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
960
|
+
* @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
961
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1138
962
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1139
|
-
* @see {@link https://
|
|
963
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1140
964
|
*/
|
|
1141
965
|
post: AsyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
1142
966
|
/**
|
|
1143
|
-
* Creates a PATCH
|
|
1144
|
-
*
|
|
1145
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
967
|
+
* Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
968
|
+
* The path and method must be declared in the interceptor schema.
|
|
1146
969
|
*
|
|
1147
|
-
* When using a
|
|
1148
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
970
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1149
971
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1150
972
|
* apply them by awaiting the handler.
|
|
1151
973
|
*
|
|
1152
974
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1153
975
|
* interceptor, and the method, path,
|
|
1154
|
-
* {@link https://
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
976
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
977
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
978
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1158
979
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1159
980
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1160
981
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1162,29 +983,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1162
983
|
*
|
|
1163
984
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1164
985
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1165
|
-
* @returns A PATCH
|
|
1166
|
-
*
|
|
1167
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
986
|
+
* @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
987
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1168
988
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1169
|
-
* @see {@link https://
|
|
989
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1170
990
|
*/
|
|
1171
991
|
patch: AsyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
1172
992
|
/**
|
|
1173
|
-
* Creates a PUT
|
|
1174
|
-
*
|
|
1175
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
993
|
+
* Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
994
|
+
* The path and method must be declared in the interceptor schema.
|
|
1176
995
|
*
|
|
1177
|
-
* When using a
|
|
1178
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
996
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1179
997
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1180
998
|
* apply them by awaiting the handler.
|
|
1181
999
|
*
|
|
1182
1000
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1183
1001
|
* interceptor, and the method, path,
|
|
1184
|
-
* {@link https://
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1002
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
1003
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
1004
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1188
1005
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1189
1006
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1190
1007
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1192,29 +1009,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1192
1009
|
*
|
|
1193
1010
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1194
1011
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1195
|
-
* @returns A PUT
|
|
1196
|
-
*
|
|
1197
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1012
|
+
* @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
1013
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1198
1014
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1199
|
-
* @see {@link https://
|
|
1015
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1200
1016
|
*/
|
|
1201
1017
|
put: AsyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
1202
1018
|
/**
|
|
1203
|
-
* Creates a DELETE
|
|
1204
|
-
*
|
|
1205
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
1019
|
+
* Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
1020
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
1206
1021
|
*
|
|
1207
|
-
* When using a
|
|
1208
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
1022
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1209
1023
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1210
1024
|
* apply them by awaiting the handler.
|
|
1211
1025
|
*
|
|
1212
1026
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1213
1027
|
* interceptor, and the method, path,
|
|
1214
|
-
* {@link https://
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1028
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
1029
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
1030
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1218
1031
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1219
1032
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1220
1033
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1222,29 +1035,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1222
1035
|
*
|
|
1223
1036
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1224
1037
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1225
|
-
* @returns A DELETE
|
|
1226
|
-
*
|
|
1227
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1038
|
+
* @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
1039
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1228
1040
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1229
|
-
* @see {@link https://
|
|
1041
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1230
1042
|
*/
|
|
1231
1043
|
delete: AsyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
1232
1044
|
/**
|
|
1233
|
-
* Creates a HEAD
|
|
1234
|
-
*
|
|
1235
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
1045
|
+
* Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
1046
|
+
* The path and method must be declared in the interceptor schema.
|
|
1236
1047
|
*
|
|
1237
|
-
* When using a
|
|
1238
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
1048
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1239
1049
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1240
1050
|
* apply them by awaiting the handler.
|
|
1241
1051
|
*
|
|
1242
1052
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1243
1053
|
* interceptor, and the method, path,
|
|
1244
|
-
* {@link https://
|
|
1245
|
-
*
|
|
1246
|
-
*
|
|
1247
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1054
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
1055
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
1056
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1248
1057
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1249
1058
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1250
1059
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1252,29 +1061,25 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1252
1061
|
*
|
|
1253
1062
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1254
1063
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1255
|
-
* @returns A HEAD
|
|
1256
|
-
*
|
|
1257
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1064
|
+
* @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
1065
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1258
1066
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1259
|
-
* @see {@link https://
|
|
1067
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1260
1068
|
*/
|
|
1261
1069
|
head: AsyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
1262
1070
|
/**
|
|
1263
|
-
* Creates an OPTIONS
|
|
1264
|
-
*
|
|
1265
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
1071
|
+
* Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
1072
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
1266
1073
|
*
|
|
1267
|
-
* When using a
|
|
1268
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
1074
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
1269
1075
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
1270
1076
|
* apply them by awaiting the handler.
|
|
1271
1077
|
*
|
|
1272
1078
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
1273
1079
|
* interceptor, and the method, path,
|
|
1274
|
-
* {@link https://
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1080
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
1081
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
1082
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
1278
1083
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
1279
1084
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
1280
1085
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -1282,11 +1087,10 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1282
1087
|
*
|
|
1283
1088
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
1284
1089
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
1285
|
-
* @returns An OPTIONS
|
|
1286
|
-
*
|
|
1287
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1090
|
+
* @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
1091
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
1288
1092
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1289
|
-
* @see {@link https://
|
|
1093
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
1290
1094
|
*/
|
|
1291
1095
|
options: AsyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
1292
1096
|
checkTimes: () => Promise<void>;
|
|
@@ -1310,8 +1114,7 @@ declare class TimesCheckError extends TypeError {
|
|
|
1310
1114
|
}
|
|
1311
1115
|
|
|
1312
1116
|
/**
|
|
1313
|
-
* Infers the schema of an
|
|
1314
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor`}.
|
|
1117
|
+
* Infers the schema of an {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor`}.
|
|
1315
1118
|
*
|
|
1316
1119
|
* @example
|
|
1317
1120
|
* import { type InferHttpInterceptorSchema } from '@zimic/http';
|
|
@@ -1335,19 +1138,11 @@ declare class TimesCheckError extends TypeError {
|
|
|
1335
1138
|
* // };
|
|
1336
1139
|
* // }
|
|
1337
1140
|
*
|
|
1338
|
-
* @see {@link https://
|
|
1141
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
1339
1142
|
*/
|
|
1340
1143
|
type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInterceptor<infer Schema> ? Schema : Interceptor extends RemoteHttpInterceptor<infer Schema> ? Schema : never;
|
|
1341
1144
|
|
|
1342
|
-
/**
|
|
1343
|
-
* Creates an HTTP interceptor.
|
|
1344
|
-
*
|
|
1345
|
-
* @param options The options for the interceptor.
|
|
1346
|
-
* @returns The created HTTP interceptor.
|
|
1347
|
-
* @throws {InvalidURLError} If the base URL is invalid.
|
|
1348
|
-
* @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
|
|
1349
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `createHttpInterceptor(options)` API reference}
|
|
1350
|
-
*/
|
|
1145
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
1351
1146
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<Schema>;
|
|
1352
1147
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
|
|
1353
1148
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
|