@zimic/interceptor 0.16.0-canary.0 → 0.16.0-canary.10

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.
Files changed (41) hide show
  1. package/README.md +4 -5
  2. package/dist/{chunk-6TSSHQW5.mjs → chunk-NTRC2S4I.mjs} +253 -312
  3. package/dist/chunk-NTRC2S4I.mjs.map +1 -0
  4. package/dist/{chunk-R2ROSKU4.js → chunk-O6ZIPCUJ.js} +254 -313
  5. package/dist/chunk-O6ZIPCUJ.js.map +1 -0
  6. package/dist/cli.js +9 -9
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cli.mjs +5 -5
  9. package/dist/cli.mjs.map +1 -1
  10. package/dist/http.d.ts +156 -176
  11. package/dist/http.js +265 -324
  12. package/dist/http.js.map +1 -1
  13. package/dist/http.mjs +263 -323
  14. package/dist/http.mjs.map +1 -1
  15. package/dist/server.d.ts +20 -46
  16. package/dist/server.js +7 -7
  17. package/dist/server.mjs +1 -1
  18. package/package.json +4 -4
  19. package/src/cli/browser/init.ts +2 -2
  20. package/src/cli/server/start.ts +2 -2
  21. package/src/http/index.ts +6 -13
  22. package/src/http/interceptor/HttpInterceptorClient.ts +30 -15
  23. package/src/http/interceptor/LocalHttpInterceptor.ts +8 -8
  24. package/src/http/interceptor/RemoteHttpInterceptor.ts +8 -8
  25. package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +22 -0
  26. package/src/http/interceptor/factory.ts +1 -1
  27. package/src/http/interceptor/types/options.ts +4 -11
  28. package/src/http/interceptor/types/public.ts +44 -12
  29. package/src/http/interceptor/types/schema.ts +2 -2
  30. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +6 -31
  31. package/src/http/requestHandler/HttpRequestHandlerClient.ts +15 -5
  32. package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +2 -2
  33. package/src/http/requestHandler/errors/TimesCheckError.ts +15 -14
  34. package/src/http/requestHandler/types/public.ts +16 -8
  35. package/src/server/index.ts +1 -11
  36. package/src/utils/console.ts +2 -2
  37. package/dist/chunk-6TSSHQW5.mjs.map +0 -1
  38. package/dist/chunk-R2ROSKU4.js.map +0 -1
  39. package/src/http/interceptorWorker/HttpInterceptorWorkerStore.ts +0 -34
  40. package/src/http/namespace/HttpInterceptorNamespace.ts +0 -81
  41. package/src/server/namespace/InterceptorServerNamespace.ts +0 -21
@@ -1,17 +1,258 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkWCQVDF3K_js = require('./chunk-WCQVDF3K.js');
4
+ var http = require('@zimic/http');
4
5
  var server = require('@whatwg-node/server');
5
6
  var http$1 = require('http');
6
- var http = require('@zimic/http');
7
- var chalk2 = require('chalk');
7
+ var color2 = require('picocolors');
8
8
  var ClientSocket = require('isomorphic-ws');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
- var chalk2__default = /*#__PURE__*/_interopDefault(chalk2);
12
+ var color2__default = /*#__PURE__*/_interopDefault(color2);
13
13
  var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
14
14
 
15
+ // src/server/errors/RunningInterceptorServerError.ts
16
+ var RunningInterceptorServerError = class extends Error {
17
+ static {
18
+ chunkWCQVDF3K_js.__name(this, "RunningInterceptorServerError");
19
+ }
20
+ constructor(additionalMessage) {
21
+ super(`The interceptor server is running.${additionalMessage}`);
22
+ this.name = "RunningInterceptorServerError";
23
+ }
24
+ };
25
+ var RunningInterceptorServerError_default = RunningInterceptorServerError;
26
+
27
+ // src/server/errors/NotRunningInterceptorServerError.ts
28
+ var NotRunningInterceptorServerError = class extends Error {
29
+ static {
30
+ chunkWCQVDF3K_js.__name(this, "NotRunningInterceptorServerError");
31
+ }
32
+ constructor() {
33
+ super("The interceptor server is not running. Did you forget to start it?");
34
+ this.name = "NotRunningInterceptorServerError";
35
+ }
36
+ };
37
+ var NotRunningInterceptorServerError_default = NotRunningInterceptorServerError;
38
+ var HttpServerTimeoutError = class extends Error {
39
+ static {
40
+ chunkWCQVDF3K_js.__name(this, "HttpServerTimeoutError");
41
+ }
42
+ };
43
+ var HttpServerStartTimeoutError = class extends HttpServerTimeoutError {
44
+ static {
45
+ chunkWCQVDF3K_js.__name(this, "HttpServerStartTimeoutError");
46
+ }
47
+ constructor(reachedTimeout) {
48
+ super(`HTTP server start timed out after ${reachedTimeout}ms.`);
49
+ this.name = "HttpServerStartTimeout";
50
+ }
51
+ };
52
+ var HttpServerStopTimeoutError = class extends HttpServerTimeoutError {
53
+ static {
54
+ chunkWCQVDF3K_js.__name(this, "HttpServerStopTimeoutError");
55
+ }
56
+ constructor(reachedTimeout) {
57
+ super(`HTTP server stop timed out after ${reachedTimeout}ms.`);
58
+ this.name = "HttpServerStopTimeout";
59
+ }
60
+ };
61
+ var DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT = 60 * 1e3;
62
+ async function startHttpServer(server, options = {}) {
63
+ const { hostname, port, timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
64
+ await new Promise((resolve, reject) => {
65
+ function handleStartError(error) {
66
+ server.off("listening", handleStartSuccess);
67
+ reject(error);
68
+ }
69
+ chunkWCQVDF3K_js.__name(handleStartError, "handleStartError");
70
+ const startTimeout = setTimeout(() => {
71
+ const timeoutError = new HttpServerStartTimeoutError(timeoutDuration);
72
+ handleStartError(timeoutError);
73
+ }, timeoutDuration);
74
+ function handleStartSuccess() {
75
+ server.off("error", handleStartError);
76
+ clearTimeout(startTimeout);
77
+ resolve();
78
+ }
79
+ chunkWCQVDF3K_js.__name(handleStartSuccess, "handleStartSuccess");
80
+ server.once("error", handleStartError);
81
+ server.listen(port, hostname, handleStartSuccess);
82
+ });
83
+ }
84
+ chunkWCQVDF3K_js.__name(startHttpServer, "startHttpServer");
85
+ async function stopHttpServer(server, options = {}) {
86
+ const { timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
87
+ if (!server.listening) {
88
+ return;
89
+ }
90
+ await new Promise((resolve, reject) => {
91
+ const stopTimeout = setTimeout(() => {
92
+ const timeoutError = new HttpServerStopTimeoutError(timeoutDuration);
93
+ reject(timeoutError);
94
+ }, timeoutDuration);
95
+ server.close((error) => {
96
+ clearTimeout(stopTimeout);
97
+ if (error) {
98
+ reject(error);
99
+ } else {
100
+ resolve();
101
+ }
102
+ });
103
+ server.closeAllConnections();
104
+ });
105
+ }
106
+ chunkWCQVDF3K_js.__name(stopHttpServer, "stopHttpServer");
107
+ function getHttpServerPort(server) {
108
+ const address = server.address();
109
+ if (typeof address === "string") {
110
+ return void 0;
111
+ } else {
112
+ return address?.port;
113
+ }
114
+ }
115
+ chunkWCQVDF3K_js.__name(getHttpServerPort, "getHttpServerPort");
116
+ function methodCanHaveResponseBody(method) {
117
+ const methodsToCompare = http.HTTP_METHODS_WITH_RESPONSE_BODY;
118
+ return methodsToCompare.includes(method);
119
+ }
120
+ chunkWCQVDF3K_js.__name(methodCanHaveResponseBody, "methodCanHaveResponseBody");
121
+
122
+ // src/utils/webSocket.ts
123
+ var WebSocketTimeoutError = class extends Error {
124
+ static {
125
+ chunkWCQVDF3K_js.__name(this, "WebSocketTimeoutError");
126
+ }
127
+ };
128
+ var WebSocketOpenTimeoutError = class extends WebSocketTimeoutError {
129
+ static {
130
+ chunkWCQVDF3K_js.__name(this, "WebSocketOpenTimeoutError");
131
+ }
132
+ constructor(reachedTimeout) {
133
+ super(`Web socket open timed out after ${reachedTimeout}ms.`);
134
+ this.name = "WebSocketOpenTimeout";
135
+ }
136
+ };
137
+ var WebSocketMessageTimeoutError = class extends WebSocketTimeoutError {
138
+ static {
139
+ chunkWCQVDF3K_js.__name(this, "WebSocketMessageTimeoutError");
140
+ }
141
+ constructor(reachedTimeout) {
142
+ super(`Web socket message timed out after ${reachedTimeout}ms.`);
143
+ this.name = "WebSocketMessageTimeout";
144
+ }
145
+ };
146
+ var WebSocketMessageAbortError = class extends WebSocketTimeoutError {
147
+ static {
148
+ chunkWCQVDF3K_js.__name(this, "WebSocketMessageAbortError");
149
+ }
150
+ constructor() {
151
+ super("Web socket message was aborted.");
152
+ this.name = "WebSocketMessageAbortError";
153
+ }
154
+ };
155
+ var WebSocketCloseTimeoutError = class extends WebSocketTimeoutError {
156
+ static {
157
+ chunkWCQVDF3K_js.__name(this, "WebSocketCloseTimeoutError");
158
+ }
159
+ constructor(reachedTimeout) {
160
+ super(`Web socket close timed out after ${reachedTimeout}ms.`);
161
+ this.name = "WebSocketCloseTimeout";
162
+ }
163
+ };
164
+ var DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT = 60 * 1e3;
165
+ var DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT = 3 * 60 * 1e3;
166
+ async function waitForOpenClientSocket(socket, options = {}) {
167
+ const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
168
+ const isAlreadyOpen = socket.readyState === socket.OPEN;
169
+ if (isAlreadyOpen) {
170
+ return;
171
+ }
172
+ await new Promise((resolve, reject) => {
173
+ function handleOpenError(error) {
174
+ socket.removeEventListener("open", handleOpenSuccess);
175
+ reject(error);
176
+ }
177
+ chunkWCQVDF3K_js.__name(handleOpenError, "handleOpenError");
178
+ const openTimeout = setTimeout(() => {
179
+ const timeoutError = new WebSocketOpenTimeoutError(timeoutDuration);
180
+ handleOpenError(timeoutError);
181
+ }, timeoutDuration);
182
+ function handleOpenSuccess() {
183
+ socket.removeEventListener("error", handleOpenError);
184
+ clearTimeout(openTimeout);
185
+ resolve();
186
+ }
187
+ chunkWCQVDF3K_js.__name(handleOpenSuccess, "handleOpenSuccess");
188
+ socket.addEventListener("open", handleOpenSuccess);
189
+ socket.addEventListener("error", handleOpenError);
190
+ });
191
+ }
192
+ chunkWCQVDF3K_js.__name(waitForOpenClientSocket, "waitForOpenClientSocket");
193
+ async function closeClientSocket(socket, options = {}) {
194
+ const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
195
+ const isAlreadyClosed = socket.readyState === socket.CLOSED;
196
+ if (isAlreadyClosed) {
197
+ return;
198
+ }
199
+ await new Promise((resolve, reject) => {
200
+ function handleCloseError(error) {
201
+ socket.removeEventListener("close", handleCloseSuccess);
202
+ reject(error);
203
+ }
204
+ chunkWCQVDF3K_js.__name(handleCloseError, "handleCloseError");
205
+ const closeTimeout = setTimeout(() => {
206
+ const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
207
+ handleCloseError(timeoutError);
208
+ }, timeoutDuration);
209
+ function handleCloseSuccess() {
210
+ socket.removeEventListener("error", handleCloseError);
211
+ clearTimeout(closeTimeout);
212
+ resolve();
213
+ }
214
+ chunkWCQVDF3K_js.__name(handleCloseSuccess, "handleCloseSuccess");
215
+ socket.addEventListener("error", handleCloseError);
216
+ socket.addEventListener("close", handleCloseSuccess);
217
+ socket.close();
218
+ });
219
+ }
220
+ chunkWCQVDF3K_js.__name(closeClientSocket, "closeClientSocket");
221
+ async function closeServerSocket(socket, options = {}) {
222
+ const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
223
+ await new Promise((resolve, reject) => {
224
+ const closeTimeout = setTimeout(() => {
225
+ const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
226
+ reject(timeoutError);
227
+ }, timeoutDuration);
228
+ for (const client of socket.clients) {
229
+ client.terminate();
230
+ }
231
+ socket.close((error) => {
232
+ clearTimeout(closeTimeout);
233
+ if (error) {
234
+ reject(error);
235
+ } else {
236
+ resolve();
237
+ }
238
+ });
239
+ });
240
+ }
241
+ chunkWCQVDF3K_js.__name(closeServerSocket, "closeServerSocket");
242
+
243
+ // src/server/constants.ts
244
+ var ALLOWED_ACCESS_CONTROL_HTTP_METHODS = http.HTTP_METHODS.join(",");
245
+ var DEFAULT_ACCESS_CONTROL_HEADERS = Object.freeze({
246
+ "access-control-allow-origin": "*",
247
+ "access-control-allow-methods": ALLOWED_ACCESS_CONTROL_HTTP_METHODS,
248
+ "access-control-allow-headers": "*",
249
+ "access-control-expose-headers": "*",
250
+ "access-control-max-age": ""
251
+ });
252
+ var DEFAULT_PREFLIGHT_STATUS_CODE = 204;
253
+ var DEFAULT_HOSTNAME = "localhost";
254
+ var DEFAULT_LOG_UNHANDLED_REQUESTS = true;
255
+
15
256
  // ../zimic-utils/dist/chunk-PAWJFY3S.mjs
16
257
  var __defProp = Object.defineProperty;
17
258
  var __name2 = /* @__PURE__ */ chunkWCQVDF3K_js.__name((target, value) => __defProp(target, "name", { value, configurable: true }), "__name");
@@ -111,92 +352,9 @@ chunkWCQVDF3K_js.__name(formatValueToLog, "formatValueToLog");
111
352
  function logWithPrefix(messageOrMessages, options = {}) {
112
353
  const { method = "log" } = options;
113
354
  const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
114
- console[method](chalk2__default.default.cyan("[@zimic/interceptor]"), ...messages);
355
+ console[method](color2__default.default.cyan("[@zimic/interceptor]"), ...messages);
115
356
  }
116
357
  chunkWCQVDF3K_js.__name(logWithPrefix, "logWithPrefix");
117
- var HttpServerTimeoutError = class extends Error {
118
- static {
119
- chunkWCQVDF3K_js.__name(this, "HttpServerTimeoutError");
120
- }
121
- };
122
- var HttpServerStartTimeoutError = class extends HttpServerTimeoutError {
123
- static {
124
- chunkWCQVDF3K_js.__name(this, "HttpServerStartTimeoutError");
125
- }
126
- constructor(reachedTimeout) {
127
- super(`HTTP server start timed out after ${reachedTimeout}ms.`);
128
- this.name = "HttpServerStartTimeout";
129
- }
130
- };
131
- var HttpServerStopTimeoutError = class extends HttpServerTimeoutError {
132
- static {
133
- chunkWCQVDF3K_js.__name(this, "HttpServerStopTimeoutError");
134
- }
135
- constructor(reachedTimeout) {
136
- super(`HTTP server stop timed out after ${reachedTimeout}ms.`);
137
- this.name = "HttpServerStopTimeout";
138
- }
139
- };
140
- var DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT = 60 * 1e3;
141
- async function startHttpServer(server, options = {}) {
142
- const { hostname, port, timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
143
- await new Promise((resolve, reject) => {
144
- function handleStartError(error) {
145
- server.off("listening", handleStartSuccess);
146
- reject(error);
147
- }
148
- chunkWCQVDF3K_js.__name(handleStartError, "handleStartError");
149
- const startTimeout = setTimeout(() => {
150
- const timeoutError = new HttpServerStartTimeoutError(timeoutDuration);
151
- handleStartError(timeoutError);
152
- }, timeoutDuration);
153
- function handleStartSuccess() {
154
- server.off("error", handleStartError);
155
- clearTimeout(startTimeout);
156
- resolve();
157
- }
158
- chunkWCQVDF3K_js.__name(handleStartSuccess, "handleStartSuccess");
159
- server.once("error", handleStartError);
160
- server.listen(port, hostname, handleStartSuccess);
161
- });
162
- }
163
- chunkWCQVDF3K_js.__name(startHttpServer, "startHttpServer");
164
- async function stopHttpServer(server, options = {}) {
165
- const { timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
166
- if (!server.listening) {
167
- return;
168
- }
169
- await new Promise((resolve, reject) => {
170
- const stopTimeout = setTimeout(() => {
171
- const timeoutError = new HttpServerStopTimeoutError(timeoutDuration);
172
- reject(timeoutError);
173
- }, timeoutDuration);
174
- server.close((error) => {
175
- clearTimeout(stopTimeout);
176
- if (error) {
177
- reject(error);
178
- } else {
179
- resolve();
180
- }
181
- });
182
- server.closeAllConnections();
183
- });
184
- }
185
- chunkWCQVDF3K_js.__name(stopHttpServer, "stopHttpServer");
186
- function getHttpServerPort(server) {
187
- const address = server.address();
188
- if (typeof address === "string") {
189
- return void 0;
190
- } else {
191
- return address?.port;
192
- }
193
- }
194
- chunkWCQVDF3K_js.__name(getHttpServerPort, "getHttpServerPort");
195
- function methodCanHaveResponseBody(method) {
196
- const methodsToCompare = http.HTTP_METHODS_WITH_RESPONSE_BODY;
197
- return methodsToCompare.includes(method);
198
- }
199
- chunkWCQVDF3K_js.__name(methodCanHaveResponseBody, "methodCanHaveResponseBody");
200
358
 
201
359
  // src/http/requestHandler/types/requests.ts
202
360
  var HTTP_INTERCEPTOR_REQUEST_HIDDEN_PROPERTIES = Object.freeze(
@@ -252,29 +410,6 @@ var InvalidJSONError = class extends SyntaxError {
252
410
  };
253
411
  var InvalidJSONError_default = InvalidJSONError;
254
412
 
255
- // src/http/interceptorWorker/HttpInterceptorWorkerStore.ts
256
- var HttpInterceptorWorkerStore = class _HttpInterceptorWorkerStore {
257
- static {
258
- chunkWCQVDF3K_js.__name(this, "HttpInterceptorWorkerStore");
259
- }
260
- static _defaultOnUnhandledRequest = {
261
- local: { ...DEFAULT_UNHANDLED_REQUEST_STRATEGY.local },
262
- remote: { ...DEFAULT_UNHANDLED_REQUEST_STRATEGY.remote }
263
- };
264
- class = _HttpInterceptorWorkerStore;
265
- defaultOnUnhandledRequest(interceptorType) {
266
- return this.class._defaultOnUnhandledRequest[interceptorType];
267
- }
268
- setDefaultOnUnhandledRequest(interceptorType, strategy) {
269
- if (interceptorType === "local") {
270
- this.class._defaultOnUnhandledRequest[interceptorType] = strategy;
271
- } else {
272
- this.class._defaultOnUnhandledRequest[interceptorType] = strategy;
273
- }
274
- }
275
- };
276
- var HttpInterceptorWorkerStore_default = HttpInterceptorWorkerStore;
277
-
278
413
  // src/http/interceptorWorker/HttpInterceptorWorker.ts
279
414
  var HttpInterceptorWorker = class _HttpInterceptorWorker {
280
415
  static {
@@ -284,7 +419,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
284
419
  isRunning = false;
285
420
  startingPromise;
286
421
  stoppingPromise;
287
- store = new HttpInterceptorWorkerStore_default();
288
422
  runningInterceptors = [];
289
423
  async sharedStart(internalStart) {
290
424
  if (this.isRunning) {
@@ -343,24 +477,18 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
343
477
  );
344
478
  }
345
479
  async getUnhandledRequestStrategyCandidates(request, interceptorType) {
346
- const globalDefaultStrategy = this.getGlobalDefaultUnhandledRequestStrategy(interceptorType);
480
+ const globalDefaultStrategy = DEFAULT_UNHANDLED_REQUEST_STRATEGY[interceptorType];
347
481
  try {
348
482
  const interceptor = this.findInterceptorByRequestBaseURL(request);
349
483
  if (!interceptor) {
350
484
  return [];
351
485
  }
352
486
  const requestClone = request.clone();
353
- const [defaultStrategy, interceptorStrategy] = await Promise.all([
354
- this.getDefaultUnhandledRequestStrategy(request, interceptorType),
355
- this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor)
356
- ]);
357
- const candidatesOrPromises = [interceptorStrategy, defaultStrategy, globalDefaultStrategy];
358
- const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined_default));
359
- return candidateStrategies;
487
+ const interceptorStrategy = await this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor);
488
+ return [interceptorStrategy, globalDefaultStrategy].filter(isDefined_default);
360
489
  } catch (error) {
361
490
  console.error(error);
362
- const candidateStrategies = [globalDefaultStrategy];
363
- return candidateStrategies;
491
+ return [globalDefaultStrategy];
364
492
  }
365
493
  }
366
494
  registerRunningInterceptor(interceptor) {
@@ -375,17 +503,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
375
503
  });
376
504
  return interceptor;
377
505
  }
378
- getGlobalDefaultUnhandledRequestStrategy(interceptorType) {
379
- return DEFAULT_UNHANDLED_REQUEST_STRATEGY[interceptorType];
380
- }
381
- async getDefaultUnhandledRequestStrategy(request, interceptorType) {
382
- const defaultStrategyOrFactory = this.store.defaultOnUnhandledRequest(interceptorType);
383
- if (typeof defaultStrategyOrFactory === "function") {
384
- const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
385
- return defaultStrategyOrFactory(parsedRequest);
386
- }
387
- return defaultStrategyOrFactory;
388
- }
389
506
  async getInterceptorUnhandledRequestStrategy(request, interceptor) {
390
507
  if (typeof interceptor.onUnhandledRequest === "function") {
391
508
  const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
@@ -599,7 +716,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
599
716
  ]);
600
717
  logWithPrefix(
601
718
  [
602
- `${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ? chalk2__default.default.yellow("bypassed") : chalk2__default.default.red("rejected")}.
719
+ `${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ? color2__default.default.yellow("bypassed") : color2__default.default.red("rejected")}.
603
720
 
604
721
  `,
605
722
  `${request.method} ${request.url}`,
@@ -674,127 +791,6 @@ function deserializeResponse(serializedResponse) {
674
791
  }
675
792
  chunkWCQVDF3K_js.__name(deserializeResponse, "deserializeResponse");
676
793
 
677
- // src/utils/webSocket.ts
678
- var WebSocketTimeoutError = class extends Error {
679
- static {
680
- chunkWCQVDF3K_js.__name(this, "WebSocketTimeoutError");
681
- }
682
- };
683
- var WebSocketOpenTimeoutError = class extends WebSocketTimeoutError {
684
- static {
685
- chunkWCQVDF3K_js.__name(this, "WebSocketOpenTimeoutError");
686
- }
687
- constructor(reachedTimeout) {
688
- super(`Web socket open timed out after ${reachedTimeout}ms.`);
689
- this.name = "WebSocketOpenTimeout";
690
- }
691
- };
692
- var WebSocketMessageTimeoutError = class extends WebSocketTimeoutError {
693
- static {
694
- chunkWCQVDF3K_js.__name(this, "WebSocketMessageTimeoutError");
695
- }
696
- constructor(reachedTimeout) {
697
- super(`Web socket message timed out after ${reachedTimeout}ms.`);
698
- this.name = "WebSocketMessageTimeout";
699
- }
700
- };
701
- var WebSocketMessageAbortError = class extends WebSocketTimeoutError {
702
- static {
703
- chunkWCQVDF3K_js.__name(this, "WebSocketMessageAbortError");
704
- }
705
- constructor() {
706
- super("Web socket message was aborted.");
707
- this.name = "WebSocketMessageAbortError";
708
- }
709
- };
710
- var WebSocketCloseTimeoutError = class extends WebSocketTimeoutError {
711
- static {
712
- chunkWCQVDF3K_js.__name(this, "WebSocketCloseTimeoutError");
713
- }
714
- constructor(reachedTimeout) {
715
- super(`Web socket close timed out after ${reachedTimeout}ms.`);
716
- this.name = "WebSocketCloseTimeout";
717
- }
718
- };
719
- var DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT = 60 * 1e3;
720
- var DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT = 3 * 60 * 1e3;
721
- async function waitForOpenClientSocket(socket, options = {}) {
722
- const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
723
- const isAlreadyOpen = socket.readyState === socket.OPEN;
724
- if (isAlreadyOpen) {
725
- return;
726
- }
727
- await new Promise((resolve, reject) => {
728
- function handleOpenError(error) {
729
- socket.removeEventListener("open", handleOpenSuccess);
730
- reject(error);
731
- }
732
- chunkWCQVDF3K_js.__name(handleOpenError, "handleOpenError");
733
- const openTimeout = setTimeout(() => {
734
- const timeoutError = new WebSocketOpenTimeoutError(timeoutDuration);
735
- handleOpenError(timeoutError);
736
- }, timeoutDuration);
737
- function handleOpenSuccess() {
738
- socket.removeEventListener("error", handleOpenError);
739
- clearTimeout(openTimeout);
740
- resolve();
741
- }
742
- chunkWCQVDF3K_js.__name(handleOpenSuccess, "handleOpenSuccess");
743
- socket.addEventListener("open", handleOpenSuccess);
744
- socket.addEventListener("error", handleOpenError);
745
- });
746
- }
747
- chunkWCQVDF3K_js.__name(waitForOpenClientSocket, "waitForOpenClientSocket");
748
- async function closeClientSocket(socket, options = {}) {
749
- const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
750
- const isAlreadyClosed = socket.readyState === socket.CLOSED;
751
- if (isAlreadyClosed) {
752
- return;
753
- }
754
- await new Promise((resolve, reject) => {
755
- function handleCloseError(error) {
756
- socket.removeEventListener("close", handleCloseSuccess);
757
- reject(error);
758
- }
759
- chunkWCQVDF3K_js.__name(handleCloseError, "handleCloseError");
760
- const closeTimeout = setTimeout(() => {
761
- const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
762
- handleCloseError(timeoutError);
763
- }, timeoutDuration);
764
- function handleCloseSuccess() {
765
- socket.removeEventListener("error", handleCloseError);
766
- clearTimeout(closeTimeout);
767
- resolve();
768
- }
769
- chunkWCQVDF3K_js.__name(handleCloseSuccess, "handleCloseSuccess");
770
- socket.addEventListener("error", handleCloseError);
771
- socket.addEventListener("close", handleCloseSuccess);
772
- socket.close();
773
- });
774
- }
775
- chunkWCQVDF3K_js.__name(closeClientSocket, "closeClientSocket");
776
- async function closeServerSocket(socket, options = {}) {
777
- const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
778
- await new Promise((resolve, reject) => {
779
- const closeTimeout = setTimeout(() => {
780
- const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
781
- reject(timeoutError);
782
- }, timeoutDuration);
783
- for (const client of socket.clients) {
784
- client.terminate();
785
- }
786
- socket.close((error) => {
787
- clearTimeout(closeTimeout);
788
- if (error) {
789
- reject(error);
790
- } else {
791
- resolve();
792
- }
793
- });
794
- });
795
- }
796
- chunkWCQVDF3K_js.__name(closeServerSocket, "closeServerSocket");
797
-
798
794
  // src/utils/crypto.ts
799
795
  var importCrypto = createCachedDynamicImport_default(async () => {
800
796
  const globalCrypto = globalThis.crypto;
@@ -1113,41 +1109,6 @@ var WebSocketServer = class extends WebSocketHandler_default {
1113
1109
  }
1114
1110
  };
1115
1111
  var WebSocketServer_default = WebSocketServer;
1116
- var ALLOWED_ACCESS_CONTROL_HTTP_METHODS = http.HTTP_METHODS.join(",");
1117
- var DEFAULT_ACCESS_CONTROL_HEADERS = Object.freeze({
1118
- "access-control-allow-origin": "*",
1119
- "access-control-allow-methods": ALLOWED_ACCESS_CONTROL_HTTP_METHODS,
1120
- "access-control-allow-headers": "*",
1121
- "access-control-expose-headers": "*",
1122
- "access-control-max-age": ""
1123
- });
1124
- var DEFAULT_PREFLIGHT_STATUS_CODE = 204;
1125
- var DEFAULT_HOSTNAME = "localhost";
1126
- var DEFAULT_LOG_UNHANDLED_REQUESTS = true;
1127
-
1128
- // src/server/errors/NotRunningInterceptorServerError.ts
1129
- var NotRunningInterceptorServerError = class extends Error {
1130
- static {
1131
- chunkWCQVDF3K_js.__name(this, "NotRunningInterceptorServerError");
1132
- }
1133
- constructor() {
1134
- super("The interceptor server is not running. Did you forget to start it?");
1135
- this.name = "NotRunningInterceptorServerError";
1136
- }
1137
- };
1138
- var NotRunningInterceptorServerError_default = NotRunningInterceptorServerError;
1139
-
1140
- // src/server/errors/RunningInterceptorServerError.ts
1141
- var RunningInterceptorServerError = class extends Error {
1142
- static {
1143
- chunkWCQVDF3K_js.__name(this, "RunningInterceptorServerError");
1144
- }
1145
- constructor(additionalMessage) {
1146
- super(`The interceptor server is running.${additionalMessage}`);
1147
- this.name = "RunningInterceptorServerError";
1148
- }
1149
- };
1150
- var RunningInterceptorServerError_default = RunningInterceptorServerError;
1151
1112
 
1152
1113
  // src/server/utils/fetch.ts
1153
1114
  async function getFetchAPI() {
@@ -1432,26 +1393,7 @@ function createInterceptorServer(options = {}) {
1432
1393
  return new InterceptorServer_default(options);
1433
1394
  }
1434
1395
  chunkWCQVDF3K_js.__name(createInterceptorServer, "createInterceptorServer");
1435
-
1436
- // src/server/namespace/InterceptorServerNamespace.ts
1437
- var InterceptorServerNamespace = class {
1438
- static {
1439
- chunkWCQVDF3K_js.__name(this, "InterceptorServerNamespace");
1440
- }
1441
- /**
1442
- * Creates an {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
1443
- *
1444
- * @param options The options to create the server.
1445
- * @returns The created server.
1446
- * @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server-programmatic-usage `zimic-interceptor server` programmatic usage}
1447
- * @see {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors Remote HTTP Interceptors} .
1448
- */
1449
- create = createInterceptorServer;
1450
- };
1451
- var InterceptorServerNamespace_default = InterceptorServerNamespace;
1452
-
1453
- // src/server/index.ts
1454
- var interceptorServer = Object.freeze(new InterceptorServerNamespace_default());
1396
+ /* istanbul ignore next -- @preserve */
1455
1397
  /* istanbul ignore if -- @preserve
1456
1398
  * This is expected not to happen since the servers are not stopped unless they are running. */
1457
1399
  /* istanbul ignore if -- @preserve
@@ -1467,7 +1409,6 @@ var interceptorServer = Object.freeze(new InterceptorServerNamespace_default());
1467
1409
  /* istanbul ignore next -- @preserve
1468
1410
  * Reply listeners are always present when notified in normal conditions. If they were not present, the request
1469
1411
  * would reach a timeout and not be responded. The empty set serves as a fallback. */
1470
- /* istanbul ignore next -- @preserve */
1471
1412
  /* istanbul ignore if -- @preserve
1472
1413
  * The HTTP server is initialized before using this method in normal conditions. */
1473
1414
  /* istanbul ignore if -- @preserve
@@ -1483,7 +1424,7 @@ exports.DEFAULT_PREFLIGHT_STATUS_CODE = DEFAULT_PREFLIGHT_STATUS_CODE;
1483
1424
  exports.NotRunningInterceptorServerError_default = NotRunningInterceptorServerError_default;
1484
1425
  exports.RunningInterceptorServerError_default = RunningInterceptorServerError_default;
1485
1426
  exports.createCachedDynamicImport_default = createCachedDynamicImport_default;
1486
- exports.interceptorServer = interceptorServer;
1427
+ exports.createInterceptorServer = createInterceptorServer;
1487
1428
  exports.logWithPrefix = logWithPrefix;
1488
- //# sourceMappingURL=chunk-R2ROSKU4.js.map
1489
- //# sourceMappingURL=chunk-R2ROSKU4.js.map
1429
+ //# sourceMappingURL=chunk-O6ZIPCUJ.js.map
1430
+ //# sourceMappingURL=chunk-O6ZIPCUJ.js.map