@zimic/interceptor 0.19.1-canary.7 → 0.19.1
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-PKURIUS2.js → chunk-3LOHF6BU.js} +2 -2
- package/dist/{chunk-PKURIUS2.js.map → chunk-3LOHF6BU.js.map} +1 -1
- package/dist/{chunk-XBLRKSEM.mjs → chunk-5RMPVTKM.mjs} +2 -2
- package/dist/{chunk-XBLRKSEM.mjs.map → chunk-5RMPVTKM.mjs.map} +1 -1
- package/dist/cli.js +18 -18
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +27 -273
- package/dist/http.js.map +1 -1
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +4 -4
- package/src/http/requestHandler/types/public.ts +12 -208
- package/src/http/requestHandler/types/requests.ts +5 -19
- package/src/http/requestHandler/types/restrictions.ts +10 -46
package/dist/server.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk3LOHF6BU_js = require('./chunk-3LOHF6BU.js');
|
|
4
4
|
require('./chunk-WCQVDF3K.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "DEFAULT_ACCESS_CONTROL_HEADERS", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk3LOHF6BU_js.DEFAULT_ACCESS_CONTROL_HEADERS; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "DEFAULT_PREFLIGHT_STATUS_CODE", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk3LOHF6BU_js.DEFAULT_PREFLIGHT_STATUS_CODE; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "NotRunningInterceptorServerError", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk3LOHF6BU_js.NotRunningInterceptorServerError_default; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "RunningInterceptorServerError", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunk3LOHF6BU_js.RunningInterceptorServerError_default; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "createInterceptorServer", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunk3LOHF6BU_js.createInterceptorServer; }
|
|
27
27
|
});
|
|
28
28
|
//# sourceMappingURL=server.js.map
|
|
29
29
|
//# sourceMappingURL=server.js.map
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, NotRunningInterceptorServerError_default as NotRunningInterceptorServerError, RunningInterceptorServerError_default as RunningInterceptorServerError, createInterceptorServer } from './chunk-
|
|
1
|
+
export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, NotRunningInterceptorServerError_default as NotRunningInterceptorServerError, RunningInterceptorServerError_default as RunningInterceptorServerError, createInterceptorServer } from './chunk-5RMPVTKM.mjs';
|
|
2
2
|
import './chunk-CGILA3WO.mjs';
|
|
3
3
|
//# sourceMappingURL=server.mjs.map
|
|
4
4
|
//# sourceMappingURL=server.mjs.map
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"api",
|
|
15
15
|
"static"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.19.1
|
|
17
|
+
"version": "0.19.1",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/zimicjs/zimic.git",
|
|
@@ -99,14 +99,14 @@
|
|
|
99
99
|
"tsup": "^8.4.0",
|
|
100
100
|
"typescript": "^5.8.3",
|
|
101
101
|
"vitest": "^3.2.1",
|
|
102
|
+
"@zimic/eslint-config-node": "0.0.0",
|
|
102
103
|
"@zimic/lint-staged-config": "0.0.0",
|
|
103
|
-
"@zimic/utils": "0.0.0",
|
|
104
104
|
"@zimic/tsconfig": "0.0.0",
|
|
105
|
-
"@zimic/
|
|
105
|
+
"@zimic/utils": "0.0.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"typescript": ">=5.0.0",
|
|
109
|
-
"@zimic/http": "^0.5.0 || 0.5.1
|
|
109
|
+
"@zimic/http": "^0.5.0 || 0.5.1"
|
|
110
110
|
},
|
|
111
111
|
"peerDependenciesMeta": {
|
|
112
112
|
"typescript": {
|
|
@@ -15,32 +15,19 @@ import {
|
|
|
15
15
|
} from './requests';
|
|
16
16
|
import { HttpRequestHandlerRestriction } from './restrictions';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* An HTTP request handler to declare responses for intercepted requests.
|
|
20
|
-
*
|
|
21
|
-
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
22
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
23
|
-
* will be used.
|
|
24
|
-
*
|
|
25
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
26
|
-
*/
|
|
18
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */
|
|
27
19
|
export interface HttpRequestHandler<
|
|
28
20
|
Schema extends HttpSchema,
|
|
29
21
|
Method extends HttpSchemaMethod<Schema>,
|
|
30
22
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
31
23
|
> {
|
|
32
24
|
/**
|
|
33
|
-
* The method that matches this handler.
|
|
34
|
-
*
|
|
35
25
|
* @readonly
|
|
36
26
|
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlermethod `handler.method` API reference}
|
|
37
27
|
*/
|
|
38
28
|
get method(): Method;
|
|
39
29
|
|
|
40
30
|
/**
|
|
41
|
-
* The path that matches this handler. The base URL of the interceptor is not included, but it is used when matching
|
|
42
|
-
* requests.
|
|
43
|
-
*
|
|
44
31
|
* @readonly
|
|
45
32
|
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerpath `handler.path` API reference}
|
|
46
33
|
*/
|
|
@@ -56,16 +43,7 @@ export interface InternalHttpRequestHandler<
|
|
|
56
43
|
client: HttpRequestHandlerClient<Schema, Method, Path, StatusCode>;
|
|
57
44
|
}
|
|
58
45
|
|
|
59
|
-
/**
|
|
60
|
-
* A local HTTP request handler to declare responses for intercepted requests. In a local handler, the mocking
|
|
61
|
-
* operations are synchronous and are executed in the same process where it was created.
|
|
62
|
-
*
|
|
63
|
-
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
64
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
65
|
-
* will be used.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
68
|
-
*/
|
|
46
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference} */
|
|
69
47
|
export interface LocalHttpRequestHandler<
|
|
70
48
|
Schema extends HttpSchema,
|
|
71
49
|
Method extends HttpSchemaMethod<Schema>,
|
|
@@ -75,113 +53,26 @@ export interface LocalHttpRequestHandler<
|
|
|
75
53
|
/** @readonly */
|
|
76
54
|
get type(): 'local';
|
|
77
55
|
|
|
78
|
-
/**
|
|
79
|
-
* Declares a restriction to intercepted request matches. `headers`, `searchParams`, and `body` are supported to limit
|
|
80
|
-
* which requests will match the handler and receive the mock response. If multiple restrictions are declared, either
|
|
81
|
-
* in a single object or with multiple calls to `handler.with()`, all of them must be met, essentially creating an AND
|
|
82
|
-
* condition.
|
|
83
|
-
*
|
|
84
|
-
* By default, restrictions use `exact: false`, meaning that any request **containing** the declared restrictions will
|
|
85
|
-
* match the handler, regardless of having more properties or values. If you want to match only requests with the
|
|
86
|
-
* exact values declared, you can use `exact: true`.
|
|
87
|
-
*
|
|
88
|
-
* A function is also supported to declare restrictions, in case they are dynamic.
|
|
89
|
-
*
|
|
90
|
-
* @param restriction The restriction to match intercepted requests.
|
|
91
|
-
* @returns The same handler, now considering the specified restriction.
|
|
92
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
93
|
-
*/
|
|
56
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
94
57
|
with: (restriction: HttpRequestHandlerRestriction<Schema, Method, Path>) => this;
|
|
95
58
|
|
|
96
|
-
/**
|
|
97
|
-
* Declares a response to return for matched intercepted requests.
|
|
98
|
-
*
|
|
99
|
-
* When the handler matches a request, it will respond with the given declaration. The response type is statically
|
|
100
|
-
* validated against the schema of the interceptor.
|
|
101
|
-
*
|
|
102
|
-
* @param declaration The response declaration or a factory to create it.
|
|
103
|
-
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
104
|
-
* status code.
|
|
105
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
106
|
-
*/
|
|
59
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
107
60
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(
|
|
108
61
|
declaration:
|
|
109
62
|
| HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, NewStatusCode>
|
|
110
63
|
| HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>,
|
|
111
64
|
) => LocalHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
|
|
112
65
|
|
|
113
|
-
/**
|
|
114
|
-
* Declares a number of intercepted requests that the handler will be able to match and return its response.
|
|
115
|
-
*
|
|
116
|
-
* If only one argument is provided, the handler will match exactly that number of requests. In case of two arguments,
|
|
117
|
-
* the handler will consider an inclusive range, matching at least the minimum (first argument) and at most the
|
|
118
|
-
* maximum (second argument) number of requests.
|
|
119
|
-
*
|
|
120
|
-
* Once the handler receives more requests than the maximum number declared, it will stop matching requests and
|
|
121
|
-
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
122
|
-
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
123
|
-
* intercepted request in the
|
|
124
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
125
|
-
*
|
|
126
|
-
* **Important**: To make sure that all expected requests were made, use
|
|
127
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} or
|
|
128
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
129
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} is
|
|
130
|
-
* generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
131
|
-
*
|
|
132
|
-
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
133
|
-
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
134
|
-
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
135
|
-
* @returns The same handler, now considering the specified number of times.
|
|
136
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
137
|
-
*/
|
|
66
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference} */
|
|
138
67
|
times: ((numberOfRequests: number) => this) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => this);
|
|
139
68
|
|
|
140
|
-
/**
|
|
141
|
-
* Checks if the handler has matched the expected number of requests declared with
|
|
142
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
143
|
-
*
|
|
144
|
-
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
145
|
-
* pointing to the
|
|
146
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
147
|
-
* that was not satisfied.
|
|
148
|
-
*
|
|
149
|
-
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in
|
|
150
|
-
* your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
151
|
-
* received data. This is useful for debugging requests that did not match a handler with
|
|
152
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
153
|
-
*
|
|
154
|
-
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
155
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
156
|
-
*/
|
|
69
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference} */
|
|
157
70
|
checkTimes: () => void;
|
|
158
71
|
|
|
159
|
-
/**
|
|
160
|
-
* Clears any response declared with
|
|
161
|
-
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
162
|
-
* restrictions declared with
|
|
163
|
-
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
164
|
-
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
165
|
-
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
166
|
-
* be intercepted.
|
|
167
|
-
*
|
|
168
|
-
* To make the handler match requests again, register a new response with
|
|
169
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
170
|
-
*
|
|
171
|
-
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
172
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
173
|
-
*/
|
|
72
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference} */
|
|
174
73
|
clear: () => this;
|
|
175
74
|
|
|
176
75
|
/**
|
|
177
|
-
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
178
|
-
* useful for testing that the correct requests were made by your application.
|
|
179
|
-
*
|
|
180
|
-
* **Important**: This method can only be used if
|
|
181
|
-
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
182
|
-
* interceptor.
|
|
183
|
-
*
|
|
184
|
-
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
185
76
|
* @readonly
|
|
186
77
|
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
187
78
|
*/
|
|
@@ -203,119 +94,32 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
203
94
|
/** @readonly */
|
|
204
95
|
get type(): 'remote';
|
|
205
96
|
|
|
206
|
-
/**
|
|
207
|
-
* Declares a restriction to intercepted request matches. `headers`, `searchParams`, and `body` are supported to limit
|
|
208
|
-
* which requests will match the handler and receive the mock response. If multiple restrictions are declared, either
|
|
209
|
-
* in a single object or with multiple calls to `handler.with()`, all of them must be met, essentially creating an AND
|
|
210
|
-
* condition.
|
|
211
|
-
*
|
|
212
|
-
* By default, restrictions use `exact: false`, meaning that any request **containing** the declared restrictions will
|
|
213
|
-
* match the handler, regardless of having more properties or values. If you want to match only requests with the
|
|
214
|
-
* exact values declared, you can use `exact: true`.
|
|
215
|
-
*
|
|
216
|
-
* A function is also supported to declare restrictions, in case they are dynamic.
|
|
217
|
-
*
|
|
218
|
-
* @param restriction The restriction to match intercepted requests.
|
|
219
|
-
* @returns The same handler, now considering the specified restriction.
|
|
220
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
221
|
-
*/
|
|
97
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
222
98
|
with: (
|
|
223
99
|
restriction: HttpRequestHandlerRestriction<Schema, Method, Path>,
|
|
224
100
|
) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
225
101
|
|
|
226
|
-
/**
|
|
227
|
-
* Declares a response to return for matched intercepted requests.
|
|
228
|
-
*
|
|
229
|
-
* When the handler matches a request, it will respond with the given declaration. The response type is statically
|
|
230
|
-
* validated against the schema of the interceptor.
|
|
231
|
-
*
|
|
232
|
-
* @param declaration The response declaration or a factory to create it.
|
|
233
|
-
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
234
|
-
* status code.
|
|
235
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
236
|
-
*/
|
|
102
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
237
103
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(
|
|
238
104
|
declaration:
|
|
239
105
|
| HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, NewStatusCode>
|
|
240
106
|
| HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>,
|
|
241
107
|
) => PendingRemoteHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
|
|
242
108
|
|
|
243
|
-
/**
|
|
244
|
-
* Declares a number of intercepted requests that the handler will be able to match and return its response.
|
|
245
|
-
*
|
|
246
|
-
* If only one argument is provided, the handler will match exactly that number of requests. In case of two arguments,
|
|
247
|
-
* the handler will consider an inclusive range, matching at least the minimum (first argument) and at most the
|
|
248
|
-
* maximum (second argument) number of requests.
|
|
249
|
-
*
|
|
250
|
-
* Once the handler receives more requests than the maximum number declared, it will stop matching requests and
|
|
251
|
-
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
252
|
-
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
253
|
-
* intercepted request in the
|
|
254
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
255
|
-
*
|
|
256
|
-
* **Important**: To make sure that all expected requests were made, use
|
|
257
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} or
|
|
258
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()`}.
|
|
259
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()`} is
|
|
260
|
-
* generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
261
|
-
*
|
|
262
|
-
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
263
|
-
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
264
|
-
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
265
|
-
* @returns The same handler, now considering the specified number of times.
|
|
266
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
267
|
-
*/
|
|
109
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference} */
|
|
268
110
|
times: ((numberOfRequests: number) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>) &
|
|
269
111
|
((
|
|
270
112
|
minNumberOfRequests: number,
|
|
271
113
|
maxNumberOfRequests: number,
|
|
272
114
|
) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>);
|
|
273
115
|
|
|
274
|
-
/**
|
|
275
|
-
* Checks if the handler has matched the expected number of requests declared with
|
|
276
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
277
|
-
*
|
|
278
|
-
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
279
|
-
* pointing to the
|
|
280
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
281
|
-
* that was not satisfied.
|
|
282
|
-
*
|
|
283
|
-
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is true in your
|
|
284
|
-
* interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
285
|
-
* received data. This is useful for debugging requests that did not match a handler with
|
|
286
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
287
|
-
*
|
|
288
|
-
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
289
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
290
|
-
*/
|
|
116
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference} */
|
|
291
117
|
checkTimes: () => Promise<void>;
|
|
292
118
|
|
|
293
|
-
/**
|
|
294
|
-
* Clears any response declared with
|
|
295
|
-
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
296
|
-
* restrictions declared with
|
|
297
|
-
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
298
|
-
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
299
|
-
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
300
|
-
* be intercepted.
|
|
301
|
-
*
|
|
302
|
-
* To make the handler match requests again, register a new response with
|
|
303
|
-
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
304
|
-
*
|
|
305
|
-
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
306
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
307
|
-
*/
|
|
119
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference} */
|
|
308
120
|
clear: () => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
309
121
|
|
|
310
122
|
/**
|
|
311
|
-
* The intercepted requests that matched this handler, along with the responses returned to each of them. This is
|
|
312
|
-
* useful for testing that the correct requests were made by your application.
|
|
313
|
-
*
|
|
314
|
-
* **Important**: This method can only be used if
|
|
315
|
-
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
316
|
-
* interceptor.
|
|
317
|
-
*
|
|
318
|
-
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
319
123
|
* @readonly
|
|
320
124
|
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
321
125
|
*/
|
|
@@ -41,7 +41,7 @@ export type HttpRequestHandlerResponseDeclarationWithHeaders<ResponseSchema exte
|
|
|
41
41
|
? { headers?: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema> }
|
|
42
42
|
: { headers: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema> };
|
|
43
43
|
|
|
44
|
-
/**
|
|
44
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
45
45
|
export type HttpRequestHandlerResponseDeclaration<
|
|
46
46
|
MethodSchema extends HttpMethodSchema = HttpMethodSchema,
|
|
47
47
|
StatusCode extends HttpStatusCode = HttpStatusCode,
|
|
@@ -53,12 +53,7 @@ export type HttpRequestHandlerResponseDeclaration<
|
|
|
53
53
|
HttpRequestHandlerResponseDeclarationWithHeaders<Default<Default<MethodSchema['response']>[StatusCode]>>
|
|
54
54
|
: never;
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* A factory to create {@link HttpRequestHandlerResponseDeclaration} objects.
|
|
58
|
-
*
|
|
59
|
-
* @param request The intercepted request.
|
|
60
|
-
* @returns The response declaration.
|
|
61
|
-
*/
|
|
56
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
62
57
|
export type HttpRequestHandlerResponseDeclarationFactory<
|
|
63
58
|
Path extends string,
|
|
64
59
|
MethodSchema extends HttpMethodSchema,
|
|
@@ -67,10 +62,7 @@ export type HttpRequestHandlerResponseDeclarationFactory<
|
|
|
67
62
|
request: Omit<HttpInterceptorRequest<Path, MethodSchema>, 'response'>,
|
|
68
63
|
) => PossiblePromise<HttpRequestHandlerResponseDeclaration<MethodSchema, StatusCode>>;
|
|
69
64
|
|
|
70
|
-
/**
|
|
71
|
-
* A strict representation of an intercepted HTTP request. The body, search params and path params are already parsed by
|
|
72
|
-
* default.
|
|
73
|
-
*/
|
|
65
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */
|
|
74
66
|
export interface HttpInterceptorRequest<Path extends string, MethodSchema extends HttpMethodSchema>
|
|
75
67
|
extends Omit<HttpRequest, keyof Body | 'headers' | 'clone'> {
|
|
76
68
|
/** The headers of the request. */
|
|
@@ -85,10 +77,7 @@ export interface HttpInterceptorRequest<Path extends string, MethodSchema extend
|
|
|
85
77
|
raw: HttpRequest<HttpRequestBodySchema<MethodSchema>, Default<HttpRequestHeadersSchema<MethodSchema>>>;
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
/**
|
|
89
|
-
* A strict representation of an intercepted HTTP response. The body, search params and path params are already parsed
|
|
90
|
-
* by default.
|
|
91
|
-
*/
|
|
80
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */
|
|
92
81
|
export interface HttpInterceptorResponse<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode>
|
|
93
82
|
extends Omit<HttpResponse, keyof Body | 'headers' | 'clone'> {
|
|
94
83
|
/** The headers of the response. */
|
|
@@ -123,10 +112,7 @@ export const HTTP_INTERCEPTOR_RESPONSE_HIDDEN_PROPERTIES = Object.freeze(
|
|
|
123
112
|
),
|
|
124
113
|
);
|
|
125
114
|
|
|
126
|
-
/**
|
|
127
|
-
* A strict representation of an intercepted HTTP request, along with its response. The body, search params and path
|
|
128
|
-
* params are already parsed by default.
|
|
129
|
-
*/
|
|
115
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference} */
|
|
130
116
|
export interface InterceptedHttpInterceptorRequest<
|
|
131
117
|
Path extends string,
|
|
132
118
|
MethodSchema extends HttpMethodSchema,
|
|
@@ -22,11 +22,7 @@ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema.Loose> = IfNeve
|
|
|
22
22
|
Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>
|
|
23
23
|
>;
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* A static headers restriction to match intercepted requests.
|
|
27
|
-
*
|
|
28
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
29
|
-
*/
|
|
25
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
30
26
|
export type HttpRequestHandlerHeadersStaticRestriction<
|
|
31
27
|
Schema extends HttpSchema,
|
|
32
28
|
Method extends HttpSchemaMethod<Schema>,
|
|
@@ -39,11 +35,7 @@ type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema.Loose
|
|
|
39
35
|
Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>
|
|
40
36
|
>;
|
|
41
37
|
|
|
42
|
-
/**
|
|
43
|
-
* A static search params restriction to match intercepted requests.
|
|
44
|
-
*
|
|
45
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
46
|
-
*/
|
|
38
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
47
39
|
export type HttpRequestHandlerSearchParamsStaticRestriction<
|
|
48
40
|
Schema extends HttpSchema,
|
|
49
41
|
Method extends HttpSchemaMethod<Schema>,
|
|
@@ -59,68 +51,40 @@ type PartialBodyOrSchema<Body extends HttpBody> =
|
|
|
59
51
|
? Body
|
|
60
52
|
: DeepPartial<Body>;
|
|
61
53
|
|
|
62
|
-
/**
|
|
63
|
-
* A static body restriction to match intercepted requests.
|
|
64
|
-
*
|
|
65
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
66
|
-
*/
|
|
54
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
67
55
|
export type HttpRequestHandlerBodyStaticRestriction<
|
|
68
56
|
Schema extends HttpSchema,
|
|
69
57
|
Method extends HttpSchemaMethod<Schema>,
|
|
70
58
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
71
59
|
> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
72
60
|
|
|
73
|
-
/**
|
|
74
|
-
* A static restriction to match intercepted requests.
|
|
75
|
-
*
|
|
76
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
77
|
-
*/
|
|
61
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
78
62
|
export interface HttpRequestHandlerStaticRestriction<
|
|
79
63
|
Schema extends HttpSchema,
|
|
80
64
|
Method extends HttpSchemaMethod<Schema>,
|
|
81
65
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
82
66
|
> {
|
|
83
|
-
/**
|
|
84
|
-
* A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
|
|
85
|
-
* must contain exactly these headers and no others.
|
|
86
|
-
*/
|
|
67
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
87
68
|
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
|
|
88
69
|
|
|
89
|
-
/**
|
|
90
|
-
* A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
|
|
91
|
-
* request must contain exactly these search params and no others.
|
|
92
|
-
*/
|
|
70
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
93
71
|
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
|
|
94
72
|
|
|
95
|
-
/**
|
|
96
|
-
* The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
|
|
97
|
-
* contain exactly this body and no other.
|
|
98
|
-
*/
|
|
73
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
99
74
|
body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
|
|
100
75
|
|
|
101
|
-
/**
|
|
102
|
-
* If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
|
|
103
|
-
* Otherwise, the request must contain **at least** them.
|
|
104
|
-
*/
|
|
76
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
105
77
|
exact?: boolean;
|
|
106
78
|
}
|
|
107
79
|
|
|
108
|
-
/**
|
|
109
|
-
* A computed restriction to match intercepted requests.
|
|
110
|
-
*
|
|
111
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
112
|
-
*/
|
|
80
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
113
81
|
export type HttpRequestHandlerComputedRestriction<
|
|
114
82
|
Schema extends HttpSchema,
|
|
115
83
|
Method extends HttpSchemaMethod<Schema>,
|
|
116
84
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
117
85
|
> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
|
|
118
86
|
|
|
119
|
-
/**
|
|
120
|
-
* A restriction to match intercepted requests.
|
|
121
|
-
*
|
|
122
|
-
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
123
|
-
*/
|
|
87
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference} */
|
|
124
88
|
export type HttpRequestHandlerRestriction<
|
|
125
89
|
Schema extends HttpSchema,
|
|
126
90
|
Method extends HttpSchemaMethod<Schema>,
|