@zimic/interceptor 1.2.3-canary.0 → 1.2.3-canary.2
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-ZPZDEDJI.mjs → chunk-XCYZ5L2M.mjs} +9 -4
- package/dist/{chunk-ZPZDEDJI.mjs.map → chunk-XCYZ5L2M.mjs.map} +1 -1
- package/dist/{chunk-EMX4G67A.js → chunk-ZU6IGW27.js} +9 -4
- package/dist/{chunk-EMX4G67A.js.map → chunk-ZU6IGW27.js.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.js +40 -23
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +40 -23
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +5 -5
- package/src/http/interceptor/HttpInterceptorClient.ts +5 -9
- package/src/http/interceptor/LocalHttpInterceptor.ts +1 -1
- package/src/http/interceptor/RemoteHttpInterceptor.ts +1 -6
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +47 -8
- package/src/server/InterceptorServer.ts +7 -2
package/dist/server.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZU6IGW27_js = require('./chunk-ZU6IGW27.js');
|
|
4
4
|
require('./chunk-DGUM43GV.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 chunkZU6IGW27_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 chunkZU6IGW27_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 chunkZU6IGW27_js.NotRunningInterceptorServerError_default; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "RunningInterceptorServerError", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkZU6IGW27_js.RunningInterceptorServerError_default; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "createInterceptorServer", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkZU6IGW27_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-XCYZ5L2M.mjs';
|
|
2
2
|
import './chunk-BJTO5JO5.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": "1.2.3-canary.
|
|
17
|
+
"version": "1.2.3-canary.2",
|
|
18
18
|
"homepage": "https://zimic.dev/docs/interceptor",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"@types/node": "^24.10.1",
|
|
111
111
|
"@types/ws": "^8.18.1",
|
|
112
112
|
"@types/yargs": "^17.0.35",
|
|
113
|
-
"@vitest/browser": "^4.0.
|
|
114
|
-
"@vitest/browser-playwright": "^4.0.
|
|
115
|
-
"@vitest/coverage-istanbul": "^4.0.
|
|
113
|
+
"@vitest/browser": "^4.0.9",
|
|
114
|
+
"@vitest/browser-playwright": "^4.0.9",
|
|
115
|
+
"@vitest/coverage-istanbul": "^4.0.9",
|
|
116
116
|
"@zimic/eslint-config-node": "workspace:*",
|
|
117
117
|
"@zimic/lint-staged-config": "workspace:*",
|
|
118
118
|
"@zimic/tsconfig": "workspace:*",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"playwright": "^1.56.1",
|
|
124
124
|
"tsup": "^8.5.1",
|
|
125
125
|
"typescript": "^5.9.3",
|
|
126
|
-
"vitest": "^4.0.
|
|
126
|
+
"vitest": "^4.0.9"
|
|
127
127
|
},
|
|
128
128
|
"peerDependencies": {
|
|
129
129
|
"@zimic/http": "^1.2.0 || workspace:*",
|
|
@@ -374,25 +374,21 @@ class HttpInterceptorClient<
|
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
clear(
|
|
378
|
-
const
|
|
377
|
+
clear() {
|
|
378
|
+
const clearPromises: Promise<AnyHttpRequestHandlerClient | void>[] = [
|
|
379
379
|
Promise.resolve(this.workerOrThrow.clearInterceptorHandlers(this)),
|
|
380
380
|
];
|
|
381
381
|
|
|
382
382
|
for (const method of HTTP_METHODS) {
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
for (const result of newClearResults) {
|
|
386
|
-
clearResults.push(Promise.resolve(result));
|
|
383
|
+
for (const result of this.clearMethodHandlers(method)) {
|
|
384
|
+
clearPromises.push(Promise.resolve(result));
|
|
387
385
|
}
|
|
388
386
|
|
|
389
387
|
const pathHandlers = this.handlers[method];
|
|
390
388
|
pathHandlers.clear();
|
|
391
389
|
}
|
|
392
390
|
|
|
393
|
-
|
|
394
|
-
void Promise.all(clearResults).then(options.onCommitSuccess, options.onCommitError);
|
|
395
|
-
}
|
|
391
|
+
return Promise.all(clearPromises);
|
|
396
392
|
}
|
|
397
393
|
|
|
398
394
|
private clearMethodHandlers(method: HttpMethod) {
|
|
@@ -157,12 +157,7 @@ class RemoteHttpInterceptor<Schema extends HttpSchema> implements PublicRemoteHt
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async clear() {
|
|
160
|
-
await
|
|
161
|
-
this.client.clear({
|
|
162
|
-
onCommitSuccess: resolve,
|
|
163
|
-
onCommitError: reject,
|
|
164
|
-
});
|
|
165
|
-
});
|
|
160
|
+
await this.client.clear();
|
|
166
161
|
}
|
|
167
162
|
}
|
|
168
163
|
|
|
@@ -5,6 +5,7 @@ import { HttpHandlerCommit, InterceptorServerWebSocketSchema } from '@/server/ty
|
|
|
5
5
|
import { importCrypto } from '@/utils/crypto';
|
|
6
6
|
import { isClientSide, isServerSide } from '@/utils/environment';
|
|
7
7
|
import { deserializeRequest, serializeResponse } from '@/utils/fetch';
|
|
8
|
+
import { WebSocketMessageAbortError } from '@/utils/webSocket';
|
|
8
9
|
import { WebSocketEventMessage } from '@/webSocket/types';
|
|
9
10
|
import WebSocketClient from '@/webSocket/WebSocketClient';
|
|
10
11
|
|
|
@@ -173,8 +174,27 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
|
|
|
173
174
|
|
|
174
175
|
this.httpHandlers.clear();
|
|
175
176
|
|
|
176
|
-
if (this.webSocketClient.isRunning) {
|
|
177
|
+
if (!this.webSocketClient.isRunning) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
177
182
|
await this.webSocketClient.request('interceptors/workers/reset', undefined);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
/* istanbul ignore next -- @preserve
|
|
185
|
+
*
|
|
186
|
+
* If the socket is closed before receiving a response, the message is aborted with an error. This can happen if
|
|
187
|
+
* we send a request message and the interceptor server closes the socket before sending a response. In this case,
|
|
188
|
+
* we can safely ignore the error because we know that the server is shutting down and resetting is no longer
|
|
189
|
+
* necessary.
|
|
190
|
+
*
|
|
191
|
+
* Due to the rare nature of this edge case, we can't reliably reproduce it in tests. */
|
|
192
|
+
const isMessageAbortError = error instanceof WebSocketMessageAbortError;
|
|
193
|
+
|
|
194
|
+
/* istanbul ignore next -- @preserve */
|
|
195
|
+
if (!isMessageAbortError) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
178
198
|
}
|
|
179
199
|
}
|
|
180
200
|
|
|
@@ -189,15 +209,34 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
|
|
|
189
209
|
}
|
|
190
210
|
}
|
|
191
211
|
|
|
192
|
-
if (this.webSocketClient.isRunning) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
212
|
+
if (!this.webSocketClient.isRunning) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const groupsToRecommit = Array.from<HttpHandler, HttpHandlerCommit>(this.httpHandlers.values(), (handler) => ({
|
|
217
|
+
id: handler.id,
|
|
218
|
+
baseURL: handler.baseURL,
|
|
219
|
+
method: handler.method,
|
|
220
|
+
path: handler.path,
|
|
221
|
+
}));
|
|
199
222
|
|
|
223
|
+
try {
|
|
200
224
|
await this.webSocketClient.request('interceptors/workers/reset', groupsToRecommit);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
/* istanbul ignore next -- @preserve
|
|
227
|
+
*
|
|
228
|
+
* If the socket is closed before receiving a response, the message is aborted with an error. This can happen if
|
|
229
|
+
* we send a request message and the interceptor server closes the socket before sending a response. In this case,
|
|
230
|
+
* we can safely ignore the error because we know that the server is shutting down and resetting is no longer
|
|
231
|
+
* necessary.
|
|
232
|
+
*
|
|
233
|
+
* Due to the rare nature of this edge case, we can't reliably reproduce it in tests. */
|
|
234
|
+
const isMessageAbortError = error instanceof WebSocketMessageAbortError;
|
|
235
|
+
|
|
236
|
+
/* istanbul ignore next -- @preserve */
|
|
237
|
+
if (!isMessageAbortError) {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
201
240
|
}
|
|
202
241
|
}
|
|
203
242
|
|
|
@@ -385,8 +385,13 @@ class InterceptorServer implements PublicInterceptorServer {
|
|
|
385
385
|
}
|
|
386
386
|
} catch (error) {
|
|
387
387
|
/* istanbul ignore next -- @preserve
|
|
388
|
-
*
|
|
389
|
-
*
|
|
388
|
+
*
|
|
389
|
+
* If the socket is closed before receiving a response, the message is aborted with an error. This can happen if
|
|
390
|
+
* we send a request message and the interceptor worker closes the socket before sending a response. In this
|
|
391
|
+
* case, we can safely ignore the error because we know that the worker is shutting down and won't handle
|
|
392
|
+
* any more requests.
|
|
393
|
+
*
|
|
394
|
+
* Due to the rare nature of this edge case, we can't reliably reproduce it in tests. */
|
|
390
395
|
const isMessageAbortError = error instanceof WebSocketMessageAbortError;
|
|
391
396
|
|
|
392
397
|
/* istanbul ignore next -- @preserve */
|