@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
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { LocalHttpInterceptor, RemoteHttpInterceptor } from './public';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Infers the schema of an
|
|
5
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor`}.
|
|
4
|
+
* Infers the schema of an {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor`}.
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
8
7
|
* import { type InferHttpInterceptorSchema } from '@zimic/http';
|
|
@@ -26,7 +25,7 @@ import { LocalHttpInterceptor, RemoteHttpInterceptor } from './public';
|
|
|
26
25
|
* // };
|
|
27
26
|
* // }
|
|
28
27
|
*
|
|
29
|
-
* @see {@link https://
|
|
28
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
30
29
|
*/
|
|
31
30
|
export type InferHttpInterceptorSchema<Interceptor> =
|
|
32
31
|
Interceptor extends LocalHttpInterceptor<infer Schema>
|
|
@@ -485,7 +485,7 @@ abstract class HttpInterceptorWorker {
|
|
|
485
485
|
formattedSearchParams,
|
|
486
486
|
'\n Body:',
|
|
487
487
|
formattedBody,
|
|
488
|
-
'\n\nLearn more: https://
|
|
488
|
+
'\n\nLearn more: https://zimic.dev/docs/interceptor/guides/http/unhandled-requests',
|
|
489
489
|
);
|
|
490
490
|
}
|
|
491
491
|
}
|
|
@@ -3,7 +3,7 @@ import { SERVICE_WORKER_FILE_NAME } from '@/cli/browser/shared/constants';
|
|
|
3
3
|
/**
|
|
4
4
|
* An error thrown when the browser mock service worker is not found.
|
|
5
5
|
*
|
|
6
|
-
* @see {@link https://
|
|
6
|
+
* @see {@link https://zimic.dev/docs/interceptor/cli/browser#zimic-interceptor-browser-init `zimic-interceptor browser init` API reference}
|
|
7
7
|
*/
|
|
8
8
|
class UnregisteredBrowserServiceWorkerError extends Error {
|
|
9
9
|
constructor() {
|
|
@@ -11,7 +11,7 @@ class UnregisteredBrowserServiceWorkerError extends Error {
|
|
|
11
11
|
'Failed to register the browser service worker: ' +
|
|
12
12
|
`script '${window.location.origin}/${SERVICE_WORKER_FILE_NAME}' not found.\n\n` +
|
|
13
13
|
'Did you forget to run `zimic-interceptor browser init <publicDirectory>`?\n\n' +
|
|
14
|
-
'Learn more: https://
|
|
14
|
+
'Learn more: https://zimic.dev/docs/interceptor/cli/browser#zimic-interceptor-browser-init',
|
|
15
15
|
);
|
|
16
16
|
this.name = 'UnregisteredBrowserServiceWorkerError';
|
|
17
17
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error thrown when trying to access requests when the interceptor is not configured to do so.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
|
|
5
5
|
*/
|
|
6
6
|
class DisabledRequestSavingError extends TypeError {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(
|
|
9
9
|
'Intercepted requests are not being saved. ' +
|
|
10
10
|
'Did you forget to use `requestSaving.enabled: true` in your interceptor?\n\n' +
|
|
11
|
-
'Learn more: https://
|
|
11
|
+
'Learn more: https://zimic.dev/docs/interceptor/api/create-http-interceptor',
|
|
12
12
|
);
|
|
13
13
|
this.name = 'DisabledRequestSavingError';
|
|
14
14
|
}
|
|
@@ -113,7 +113,7 @@ function createMessageDiffs({ requestSaving, unmatchedRequestGroups }: TimesChec
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function createMessageFooter() {
|
|
116
|
-
return 'Learn more: https://
|
|
116
|
+
return 'Learn more: https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes';
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
function createMessage(options: TimesCheckErrorOptions) {
|
|
@@ -19,10 +19,10 @@ import { HttpRequestHandlerRestriction } from './restrictions';
|
|
|
19
19
|
* An HTTP request handler to declare responses for intercepted requests.
|
|
20
20
|
*
|
|
21
21
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
22
|
-
* {@link https://
|
|
22
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
23
23
|
* will be used.
|
|
24
24
|
*
|
|
25
|
-
* @see {@link https://
|
|
25
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
26
26
|
*/
|
|
27
27
|
export interface HttpRequestHandler<
|
|
28
28
|
Schema extends HttpSchema,
|
|
@@ -33,7 +33,7 @@ export interface HttpRequestHandler<
|
|
|
33
33
|
* The method that matches this handler.
|
|
34
34
|
*
|
|
35
35
|
* @readonly
|
|
36
|
-
* @see {@link https://
|
|
36
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlermethod `handler.method` API reference}
|
|
37
37
|
*/
|
|
38
38
|
get method(): Method;
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ export interface HttpRequestHandler<
|
|
|
42
42
|
* requests.
|
|
43
43
|
*
|
|
44
44
|
* @readonly
|
|
45
|
-
* @see {@link https://
|
|
45
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerpath `handler.path` API reference}
|
|
46
46
|
*/
|
|
47
47
|
get path(): Path;
|
|
48
48
|
}
|
|
@@ -61,10 +61,10 @@ export interface InternalHttpRequestHandler<
|
|
|
61
61
|
* operations are synchronous and are executed in the same process where it was created.
|
|
62
62
|
*
|
|
63
63
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
64
|
-
* {@link https://
|
|
64
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
65
65
|
* will be used.
|
|
66
66
|
*
|
|
67
|
-
* @see {@link https://
|
|
67
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
68
68
|
*/
|
|
69
69
|
export interface LocalHttpRequestHandler<
|
|
70
70
|
Schema extends HttpSchema,
|
|
@@ -89,7 +89,7 @@ export interface LocalHttpRequestHandler<
|
|
|
89
89
|
*
|
|
90
90
|
* @param restriction The restriction to match intercepted requests.
|
|
91
91
|
* @returns The same handler, now considering the specified restriction.
|
|
92
|
-
* @see {@link https://
|
|
92
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
93
93
|
*/
|
|
94
94
|
with: (restriction: HttpRequestHandlerRestriction<Schema, Method, Path>) => this;
|
|
95
95
|
|
|
@@ -102,7 +102,7 @@ export interface LocalHttpRequestHandler<
|
|
|
102
102
|
* @param declaration The response declaration or a factory to create it.
|
|
103
103
|
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
104
104
|
* status code.
|
|
105
|
-
* @see {@link https://
|
|
105
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
106
106
|
*/
|
|
107
107
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(
|
|
108
108
|
declaration:
|
|
@@ -121,57 +121,55 @@ export interface LocalHttpRequestHandler<
|
|
|
121
121
|
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
122
122
|
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
123
123
|
* intercepted request in the
|
|
124
|
-
* {@link https://
|
|
124
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
125
125
|
*
|
|
126
126
|
* **Important**: To make sure that all expected requests were made, use
|
|
127
|
-
* {@link https://
|
|
128
|
-
*
|
|
129
|
-
* {@link https://
|
|
130
|
-
*
|
|
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
131
|
*
|
|
132
132
|
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
133
133
|
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
134
134
|
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
135
135
|
* @returns The same handler, now considering the specified number of times.
|
|
136
|
-
* @see {@link https://
|
|
136
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
137
137
|
*/
|
|
138
138
|
times: ((numberOfRequests: number) => this) & ((minNumberOfRequests: number, maxNumberOfRequests: number) => this);
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Checks if the handler has matched the expected number of requests declared with
|
|
142
|
-
* {@link https://
|
|
142
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
143
143
|
*
|
|
144
144
|
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
145
145
|
* pointing to the
|
|
146
|
-
* {@link https://
|
|
146
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
147
147
|
* that was not satisfied.
|
|
148
148
|
*
|
|
149
|
-
* When
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
154
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
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}.
|
|
155
153
|
*
|
|
156
154
|
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
157
|
-
* @see {@link https://
|
|
155
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
158
156
|
*/
|
|
159
157
|
checkTimes: () => void;
|
|
160
158
|
|
|
161
159
|
/**
|
|
162
160
|
* Clears any response declared with
|
|
163
|
-
* [`handler.respond(declaration)`](https://
|
|
161
|
+
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
164
162
|
* restrictions declared with
|
|
165
|
-
* [`handler.with(restriction)`](https://
|
|
163
|
+
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
166
164
|
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
167
165
|
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
168
166
|
* be intercepted.
|
|
169
167
|
*
|
|
170
168
|
* To make the handler match requests again, register a new response with
|
|
171
|
-
* {@link https://
|
|
169
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
172
170
|
*
|
|
173
171
|
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
174
|
-
* @see {@link https://
|
|
172
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
175
173
|
*/
|
|
176
174
|
clear: () => this;
|
|
177
175
|
|
|
@@ -180,25 +178,21 @@ export interface LocalHttpRequestHandler<
|
|
|
180
178
|
* useful for testing that the correct requests were made by your application.
|
|
181
179
|
*
|
|
182
180
|
* **Important**: This method can only be used if
|
|
183
|
-
* {@link https://
|
|
184
|
-
*
|
|
185
|
-
* `true` in the interceptor. See
|
|
186
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
187
|
-
* for more information.
|
|
181
|
+
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
182
|
+
* interceptor.
|
|
188
183
|
*
|
|
189
184
|
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
190
185
|
* @readonly
|
|
191
|
-
* @see {@link https://
|
|
186
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
192
187
|
*/
|
|
193
188
|
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
194
189
|
}
|
|
195
190
|
|
|
196
191
|
/**
|
|
197
192
|
* A synced remote HTTP request handler. When a remote handler is synced, it is guaranteed that all of the mocking
|
|
198
|
-
* operations were committed to the connected
|
|
199
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
193
|
+
* operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
200
194
|
*
|
|
201
|
-
* @see {@link https://
|
|
195
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
202
196
|
*/
|
|
203
197
|
export interface SyncedRemoteHttpRequestHandler<
|
|
204
198
|
Schema extends HttpSchema,
|
|
@@ -223,7 +217,7 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
223
217
|
*
|
|
224
218
|
* @param restriction The restriction to match intercepted requests.
|
|
225
219
|
* @returns The same handler, now considering the specified restriction.
|
|
226
|
-
* @see {@link https://
|
|
220
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
227
221
|
*/
|
|
228
222
|
with: (
|
|
229
223
|
restriction: HttpRequestHandlerRestriction<Schema, Method, Path>,
|
|
@@ -238,7 +232,7 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
238
232
|
* @param declaration The response declaration or a factory to create it.
|
|
239
233
|
* @returns The same handler, now including type information about the response declaration based on the specified
|
|
240
234
|
* status code.
|
|
241
|
-
* @see {@link https://
|
|
235
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference}
|
|
242
236
|
*/
|
|
243
237
|
respond: <NewStatusCode extends HttpResponseSchemaStatusCode<Default<Default<Schema[Path][Method]>['response']>>>(
|
|
244
238
|
declaration:
|
|
@@ -257,20 +251,19 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
257
251
|
* returning its response. In this case, Zimic will try other handlers until one eligible is found, otherwise the
|
|
258
252
|
* request will be either bypassed or rejected. Learn more about how Zimic decides which handler to use for an
|
|
259
253
|
* intercepted request in the
|
|
260
|
-
* {@link https://
|
|
254
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}.
|
|
261
255
|
*
|
|
262
256
|
* **Important**: To make sure that all expected requests were made, use
|
|
263
|
-
* {@link https://
|
|
264
|
-
*
|
|
265
|
-
* {@link https://
|
|
266
|
-
*
|
|
267
|
-
* is generally preferred, as it checks all handlers created by the interceptor with a single call.
|
|
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.
|
|
268
261
|
*
|
|
269
262
|
* @param numberOfRequests The number of times the handler should match intercepted requests.
|
|
270
263
|
* @param minNumberOfRequests The minimum number of times the handler should match intercepted requests.
|
|
271
264
|
* @param maxNumberOfRequests The maximum number of times the handler should match intercepted requests.
|
|
272
265
|
* @returns The same handler, now considering the specified number of times.
|
|
273
|
-
* @see {@link https://
|
|
266
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
274
267
|
*/
|
|
275
268
|
times: ((numberOfRequests: number) => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>) &
|
|
276
269
|
((
|
|
@@ -280,39 +273,37 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
280
273
|
|
|
281
274
|
/**
|
|
282
275
|
* Checks if the handler has matched the expected number of requests declared with
|
|
283
|
-
* {@link https://
|
|
276
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
284
277
|
*
|
|
285
278
|
* If the handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error
|
|
286
279
|
* pointing to the
|
|
287
|
-
* {@link https://
|
|
280
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()` API reference}
|
|
288
281
|
* that was not satisfied.
|
|
289
282
|
*
|
|
290
|
-
* When
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
295
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
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}.
|
|
296
287
|
*
|
|
297
288
|
* @throws {TimesCheckError} If the handler has matched less or more requests than the expected number of requests.
|
|
298
|
-
* @see {@link https://
|
|
289
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerchecktimes `handler.checkTimes()` API reference}
|
|
299
290
|
*/
|
|
300
291
|
checkTimes: () => Promise<void>;
|
|
301
292
|
|
|
302
293
|
/**
|
|
303
294
|
* Clears any response declared with
|
|
304
|
-
* [`handler.respond(declaration)`](https://
|
|
295
|
+
* [`handler.respond(declaration)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerresponddeclaration),
|
|
305
296
|
* restrictions declared with
|
|
306
|
-
* [`handler.with(restriction)`](https://
|
|
297
|
+
* [`handler.with(restriction)`](https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction),
|
|
307
298
|
* and intercepted requests, making the handler stop matching requests. The next handler, created before this one,
|
|
308
299
|
* that matches the same method and path will be used if present. If not, the requests of the method and path will not
|
|
309
300
|
* be intercepted.
|
|
310
301
|
*
|
|
311
302
|
* To make the handler match requests again, register a new response with
|
|
312
|
-
* {@link https://
|
|
303
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()`}.
|
|
313
304
|
*
|
|
314
305
|
* @returns The same handler, now cleared of any declared responses, restrictions, and intercepted requests.
|
|
315
|
-
* @see {@link https://
|
|
306
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerclear `handler.clear()` API reference}
|
|
316
307
|
*/
|
|
317
308
|
clear: () => PendingRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>;
|
|
318
309
|
|
|
@@ -321,28 +312,24 @@ export interface SyncedRemoteHttpRequestHandler<
|
|
|
321
312
|
* useful for testing that the correct requests were made by your application.
|
|
322
313
|
*
|
|
323
314
|
* **Important**: This method can only be used if
|
|
324
|
-
* {@link https://
|
|
325
|
-
*
|
|
326
|
-
* `true` in the interceptor. See
|
|
327
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
328
|
-
* for more information.
|
|
315
|
+
* {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in the
|
|
316
|
+
* interceptor.
|
|
329
317
|
*
|
|
330
318
|
* @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
|
|
331
319
|
* @readonly
|
|
332
|
-
* @see {@link https://
|
|
320
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrequests `handler.requests` API reference}
|
|
333
321
|
*/
|
|
334
322
|
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
335
323
|
}
|
|
336
324
|
|
|
337
325
|
/**
|
|
338
326
|
* A pending remote HTTP request handler. When a remote handler is pending, it is not guaranteed that all of the mocking
|
|
339
|
-
* operations were committed to the connected
|
|
340
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
327
|
+
* operations were committed to the connected {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
341
328
|
*
|
|
342
329
|
* To commit a remote interceptor, you can `await` it or use the methods {@link then handler.then()},
|
|
343
330
|
* {@link catch handler.catch()}, and {@link finally handler.finally()}.
|
|
344
331
|
*
|
|
345
|
-
* @see {@link https://
|
|
332
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
346
333
|
*/
|
|
347
334
|
export interface PendingRemoteHttpRequestHandler<
|
|
348
335
|
Schema extends HttpSchema,
|
|
@@ -352,7 +339,7 @@ export interface PendingRemoteHttpRequestHandler<
|
|
|
352
339
|
> extends SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode> {
|
|
353
340
|
/**
|
|
354
341
|
* Waits for the remote handler to be synced with the connected
|
|
355
|
-
* {@link https://
|
|
342
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
356
343
|
*/
|
|
357
344
|
then: <FulfilledResult = SyncedRemoteHttpRequestHandler<Schema, Method, Path, StatusCode>, RejectedResult = never>(
|
|
358
345
|
onFulfilled?:
|
|
@@ -365,7 +352,7 @@ export interface PendingRemoteHttpRequestHandler<
|
|
|
365
352
|
|
|
366
353
|
/**
|
|
367
354
|
* Waits for the remote handler to be synced with the connected
|
|
368
|
-
* {@link https://
|
|
355
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
369
356
|
*/
|
|
370
357
|
catch: <RejectedResult = never>(
|
|
371
358
|
onRejected?: ((reason: unknown) => PossiblePromise<RejectedResult>) | null,
|
|
@@ -373,7 +360,7 @@ export interface PendingRemoteHttpRequestHandler<
|
|
|
373
360
|
|
|
374
361
|
/**
|
|
375
362
|
* Waits for the remote handler to be synced with the connected
|
|
376
|
-
* {@link https://
|
|
363
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
377
364
|
*/
|
|
378
365
|
finally: (
|
|
379
366
|
onFinally?: (() => void) | null,
|
|
@@ -383,13 +370,13 @@ export interface PendingRemoteHttpRequestHandler<
|
|
|
383
370
|
/**
|
|
384
371
|
* A remote HTTP request handler to declare responses for intercepted requests. In a remote handler, the mocking
|
|
385
372
|
* operations are asynchronous and include remote calls to the connected
|
|
386
|
-
* {@link https://
|
|
373
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
387
374
|
*
|
|
388
375
|
* When multiple handlers of the same interceptor match the same method and path, the _last_ handler created with
|
|
389
|
-
* {@link https://
|
|
376
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptormethodpath `interceptor.<method>(path)`}
|
|
390
377
|
* will be used.
|
|
391
378
|
*
|
|
392
|
-
* @see {@link https://
|
|
379
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler` API reference}
|
|
393
380
|
*/
|
|
394
381
|
export type RemoteHttpRequestHandler<
|
|
395
382
|
Schema extends HttpSchema,
|
|
@@ -25,7 +25,7 @@ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema.Loose> = IfNeve
|
|
|
25
25
|
/**
|
|
26
26
|
* A static headers restriction to match intercepted requests.
|
|
27
27
|
*
|
|
28
|
-
* @see {@link https://
|
|
28
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
29
29
|
*/
|
|
30
30
|
export type HttpRequestHandlerHeadersStaticRestriction<
|
|
31
31
|
Schema extends HttpSchema,
|
|
@@ -42,7 +42,7 @@ type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema.Loose
|
|
|
42
42
|
/**
|
|
43
43
|
* A static search params restriction to match intercepted requests.
|
|
44
44
|
*
|
|
45
|
-
* @see {@link https://
|
|
45
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
46
46
|
*/
|
|
47
47
|
export type HttpRequestHandlerSearchParamsStaticRestriction<
|
|
48
48
|
Schema extends HttpSchema,
|
|
@@ -62,7 +62,7 @@ type PartialBodyOrSchema<Body extends HttpBody> =
|
|
|
62
62
|
/**
|
|
63
63
|
* A static body restriction to match intercepted requests.
|
|
64
64
|
*
|
|
65
|
-
* @see {@link https://
|
|
65
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
66
66
|
*/
|
|
67
67
|
export type HttpRequestHandlerBodyStaticRestriction<
|
|
68
68
|
Schema extends HttpSchema,
|
|
@@ -73,7 +73,7 @@ export type HttpRequestHandlerBodyStaticRestriction<
|
|
|
73
73
|
/**
|
|
74
74
|
* A static restriction to match intercepted requests.
|
|
75
75
|
*
|
|
76
|
-
* @see {@link https://
|
|
76
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
77
77
|
*/
|
|
78
78
|
export interface HttpRequestHandlerStaticRestriction<
|
|
79
79
|
Schema extends HttpSchema,
|
|
@@ -108,7 +108,7 @@ export interface HttpRequestHandlerStaticRestriction<
|
|
|
108
108
|
/**
|
|
109
109
|
* A computed restriction to match intercepted requests.
|
|
110
110
|
*
|
|
111
|
-
* @see {@link https://
|
|
111
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
112
112
|
*/
|
|
113
113
|
export type HttpRequestHandlerComputedRestriction<
|
|
114
114
|
Schema extends HttpSchema,
|
|
@@ -119,7 +119,7 @@ export type HttpRequestHandlerComputedRestriction<
|
|
|
119
119
|
/**
|
|
120
120
|
* A restriction to match intercepted requests.
|
|
121
121
|
*
|
|
122
|
-
* @see {@link https://
|
|
122
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction `handler.with()` API reference}
|
|
123
123
|
*/
|
|
124
124
|
export type HttpRequestHandlerRestriction<
|
|
125
125
|
Schema extends HttpSchema,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error thrown when an interceptor token is invalid.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
|
|
5
5
|
*/
|
|
6
6
|
class InvalidInterceptorTokenError extends Error {
|
|
7
7
|
constructor(tokenId: string) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error thrown when an interceptor token file is invalid.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
|
|
5
5
|
*/
|
|
6
6
|
class InvalidInterceptorTokenFileError extends Error {
|
|
7
7
|
constructor(tokenFilePath: string, validationErrorMessage: string) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error thrown when an interceptor token value is invalid.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
|
|
5
5
|
*/
|
|
6
6
|
class InvalidInterceptorTokenValueError extends Error {
|
|
7
7
|
constructor(tokenValue: string) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An error thrown when the interceptor server is running and some operation requires it to be stopped first.
|
|
3
3
|
*
|
|
4
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `@zimic/interceptor/server` API reference}
|
|
5
5
|
*/
|
|
6
6
|
class RunningInterceptorServerError extends Error {
|
|
7
7
|
constructor(additionalMessage: string) {
|
package/src/server/factory.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { InterceptorServerOptions } from './types/options';
|
|
|
3
3
|
import { InterceptorServer as PublicInterceptorServer } from './types/public';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates an {@link https://
|
|
6
|
+
* Creates an {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
7
7
|
*
|
|
8
8
|
* @param options The options to create the server.
|
|
9
9
|
* @returns The created server.
|
|
10
|
-
* @see {@link https://
|
|
11
|
-
* @see {@link https://
|
|
10
|
+
* @see {@link https://zimic.dev/docs/interceptor/cli/server-programmatic-usage `zimic-interceptor server` programmatic usage}
|
|
11
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors Remote HTTP Interceptors} .
|
|
12
12
|
*/
|
|
13
13
|
export function createInterceptorServer(options: InterceptorServerOptions = {}): PublicInterceptorServer {
|
|
14
14
|
return new InterceptorServer(options);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The options to create an
|
|
3
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
2
|
+
* The options to create an {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
|
|
4
3
|
*
|
|
5
|
-
* @see {@link https://
|
|
4
|
+
* @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
|
|
6
5
|
*/
|
|
7
6
|
export interface InterceptorServerOptions {
|
|
8
7
|
/**
|