@zimic/interceptor 1.4.0 → 1.4.1-canary.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/server.js CHANGED
@@ -1,29 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var chunk4COMUARA_js = require('./chunk-4COMUARA.js');
3
+ var chunk3W3A4TJ5_js = require('./chunk-3W3A4TJ5.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 chunk4COMUARA_js.DEFAULT_ACCESS_CONTROL_HEADERS; }
10
+ get: function () { return chunk3W3A4TJ5_js.DEFAULT_ACCESS_CONTROL_HEADERS; }
11
11
  });
12
12
  Object.defineProperty(exports, "DEFAULT_PREFLIGHT_STATUS_CODE", {
13
13
  enumerable: true,
14
- get: function () { return chunk4COMUARA_js.DEFAULT_PREFLIGHT_STATUS_CODE; }
14
+ get: function () { return chunk3W3A4TJ5_js.DEFAULT_PREFLIGHT_STATUS_CODE; }
15
15
  });
16
16
  Object.defineProperty(exports, "NotRunningInterceptorServerError", {
17
17
  enumerable: true,
18
- get: function () { return chunk4COMUARA_js.NotRunningInterceptorServerError_default; }
18
+ get: function () { return chunk3W3A4TJ5_js.NotRunningInterceptorServerError_default; }
19
19
  });
20
20
  Object.defineProperty(exports, "RunningInterceptorServerError", {
21
21
  enumerable: true,
22
- get: function () { return chunk4COMUARA_js.RunningInterceptorServerError_default; }
22
+ get: function () { return chunk3W3A4TJ5_js.RunningInterceptorServerError_default; }
23
23
  });
24
24
  Object.defineProperty(exports, "createInterceptorServer", {
25
25
  enumerable: true,
26
- get: function () { return chunk4COMUARA_js.createInterceptorServer; }
26
+ get: function () { return chunk3W3A4TJ5_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-VFCCTIDU.mjs';
1
+ export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, NotRunningInterceptorServerError_default as NotRunningInterceptorServerError, RunningInterceptorServerError_default as RunningInterceptorServerError, createInterceptorServer } from './chunk-F3VMDYHM.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.4.0",
17
+ "version": "1.4.1-canary.1",
18
18
  "homepage": "https://zimic.dev/docs/interceptor",
19
19
  "repository": {
20
20
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "provenance": true
36
36
  },
37
37
  "engines": {
38
- "node": ">=20.0.0"
38
+ "node": ">=22.0.0"
39
39
  },
40
40
  "license": "MIT",
41
41
  "files": [
@@ -97,11 +97,11 @@
97
97
  "dependencies": {
98
98
  "@whatwg-node/server": "0.10.18",
99
99
  "isomorphic-ws": "5.0.0",
100
- "msw": "2.13.6",
100
+ "msw": "2.14.2",
101
101
  "picocolors": "^1.1.1",
102
102
  "ws": "8.20.0",
103
103
  "yargs": "18.0.0",
104
- "zod": "^4.3.6"
104
+ "zod": "^4.4.2"
105
105
  },
106
106
  "devDependencies": {
107
107
  "@types/node": "^25.6.0",
@@ -4,7 +4,6 @@ import { validatePathParams } from '@zimic/utils/url';
4
4
 
5
5
  import UnsupportedResponseBypassError from '@/server/errors/UnsupportedResponseBypassError';
6
6
  import { HttpHandlerCommit, InterceptorServerWebSocketSchema } from '@/server/types/schema';
7
- import { importCrypto } from '@/utils/crypto';
8
7
  import { isClientSide, isServerSide } from '@/utils/environment';
9
8
  import { deserializeRequest, serializeResponse } from '@/utils/fetch';
10
9
  import { methodCanHaveResponseBody } from '@/utils/http';
@@ -150,8 +149,6 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
150
149
 
151
150
  validatePathParams(path);
152
151
 
153
- const crypto = await importCrypto();
154
-
155
152
  const handler: HttpHandler = {
156
153
  id: crypto.randomUUID(),
157
154
  baseURL: interceptor.baseURLAsString,
@@ -289,7 +289,7 @@ class InterceptorServer implements PublicInterceptorServer {
289
289
  }
290
290
 
291
291
  private handleHttpRequest = async (nodeRequest: IncomingMessage, nodeResponse: ServerResponse) => {
292
- const request = normalizeNodeRequest(nodeRequest, await getFetchAPI());
292
+ const request = normalizeNodeRequest(nodeRequest, getFetchAPI());
293
293
  const serializedRequest = await serializeRequest(request);
294
294
 
295
295
  try {
@@ -1,10 +1,6 @@
1
1
  import { FetchAPI } from '@whatwg-node/server';
2
2
 
3
- import { importFile } from '@/utils/files';
4
-
5
- export async function getFetchAPI(): Promise<FetchAPI> {
6
- const File = await importFile();
7
-
3
+ export function getFetchAPI(): FetchAPI {
8
4
  return {
9
5
  fetch,
10
6
  Request,
@@ -1,18 +1,6 @@
1
1
  import { createCachedDynamicImport } from '@zimic/utils/import';
2
2
  import type fs from 'fs';
3
3
 
4
- export const importFile = createCachedDynamicImport(
5
- /* istanbul ignore next -- @preserve
6
- * Ignoring as Node.js >=20 provides a global File and the import fallback won't run. */
7
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
8
- async () => globalThis.File ?? (await import('buffer')).File,
9
- );
10
-
11
- export function isGlobalFileAvailable() {
12
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
13
- return globalThis.File !== undefined;
14
- }
15
-
16
4
  export const importFilesystem = createCachedDynamicImport<typeof fs>(() => import('fs'));
17
5
 
18
6
  export async function pathExists(path: string) {
@@ -4,7 +4,6 @@ import { Logger } from '@zimic/utils/logging';
4
4
  import color from 'picocolors';
5
5
 
6
6
  import { isClientSide } from './environment';
7
- import { isGlobalFileAvailable } from './files';
8
7
 
9
8
  export const logger = new Logger({
10
9
  prefix: color.cyan('[@zimic/interceptor]'),
@@ -52,7 +51,7 @@ export function stringifyValueToLog(
52
51
  return `FormData ${stringifyValueToLog(value.toObject())}`;
53
52
  }
54
53
 
55
- if (isGlobalFileAvailable() && value instanceof File) {
54
+ if (value instanceof File) {
56
55
  return `File { name: '${value.name}', type: '${value.type}', size: ${value.size} }`;
57
56
  }
58
57
 
@@ -1,7 +1,6 @@
1
1
  import { Collection } from '@zimic/utils/types';
2
2
  import ClientSocket from 'isomorphic-ws';
3
3
 
4
- import { importCrypto } from '@/utils/crypto';
5
4
  import {
6
5
  DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT,
7
6
  DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT,
@@ -194,7 +193,7 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
194
193
 
195
194
  const listenerPromises = Array.from(listeners, async (listener) => {
196
195
  const replyData = await listener(message, socket);
197
- await this.reply(message, replyData, { sockets: [socket] });
196
+ this.reply(message, replyData, { sockets: [socket] });
198
197
  });
199
198
 
200
199
  await Promise.all(listenerPromises);
@@ -207,12 +206,10 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
207
206
  await Promise.all(closingPromises);
208
207
  }
209
208
 
210
- private async createEventMessage<Channel extends WebSocketChannel<Schema>>(
209
+ private createEventMessage<Channel extends WebSocketChannel<Schema>>(
211
210
  channel: Channel,
212
211
  eventData: WebSocketEventMessage<Schema, Channel>['data'],
213
212
  ) {
214
- const crypto = await importCrypto();
215
-
216
213
  const eventMessage: WebSocketEventMessage<Schema, Channel> = {
217
214
  id: crypto.randomUUID(),
218
215
  channel,
@@ -221,14 +218,14 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
221
218
  return eventMessage;
222
219
  }
223
220
 
224
- async send<Channel extends WebSocketChannelWithNoReply<Schema>>(
221
+ send<Channel extends WebSocketChannelWithNoReply<Schema>>(
225
222
  channel: Channel,
226
223
  eventData: WebSocketEventMessage<Schema, Channel>['data'],
227
224
  options: {
228
225
  sockets?: Collection<ClientSocket>;
229
226
  } = {},
230
227
  ) {
231
- const event = await this.createEventMessage(channel, eventData);
228
+ const event = this.createEventMessage(channel, eventData);
232
229
  this.sendMessage(event, options.sockets);
233
230
  }
234
231
 
@@ -239,7 +236,7 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
239
236
  sockets?: Collection<ClientSocket>;
240
237
  } = {},
241
238
  ) {
242
- const request = await this.createEventMessage(channel, requestData);
239
+ const request = this.createEventMessage(channel, requestData);
243
240
  this.sendMessage(request, options.sockets);
244
241
 
245
242
  const response = await this.waitForReply(channel, request, options.sockets);
@@ -310,14 +307,14 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
310
307
  return 'requestId' in message;
311
308
  }
312
309
 
313
- async reply<Channel extends WebSocketChannel<Schema>>(
310
+ reply<Channel extends WebSocketChannel<Schema>>(
314
311
  request: WebSocketEventMessage<Schema, Channel>,
315
312
  replyData: WebSocketReplyMessage<Schema, Channel>['data'],
316
313
  options: {
317
314
  sockets: Collection<ClientSocket>;
318
315
  },
319
316
  ) {
320
- const reply = await this.createReplyMessage(request, replyData);
317
+ const reply = this.createReplyMessage(request, replyData);
321
318
 
322
319
  // If this handler received a request and was stopped before responding, discard any pending replies.
323
320
  if (this.isRunning) {
@@ -325,12 +322,10 @@ abstract class WebSocketHandler<Schema extends WebSocketSchema> {
325
322
  }
326
323
  }
327
324
 
328
- private async createReplyMessage<Channel extends WebSocketChannel<Schema>>(
325
+ private createReplyMessage<Channel extends WebSocketChannel<Schema>>(
329
326
  request: WebSocketEventMessage<Schema, Channel>,
330
327
  replyData: WebSocketReplyMessage<Schema, Channel>['data'],
331
328
  ) {
332
- const crypto = await importCrypto();
333
-
334
329
  const replyMessage: WebSocketReplyMessage<Schema, Channel> = {
335
330
  id: crypto.randomUUID(),
336
331
  channel: request.channel,