@zimic/interceptor 0.14.0-canary.19 → 0.14.0-canary.21

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 (55) hide show
  1. package/dist/{chunk-3XWHITKR.mjs → chunk-5ESJW32X.mjs} +90 -165
  2. package/dist/chunk-5ESJW32X.mjs.map +1 -0
  3. package/dist/{chunk-SWLQ2IF6.js → chunk-JIUQ7G6N.js} +90 -165
  4. package/dist/chunk-JIUQ7G6N.js.map +1 -0
  5. package/dist/cli.js +7 -7
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cli.mjs +3 -3
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/http.d.ts +1 -12
  10. package/dist/http.js +182 -180
  11. package/dist/http.js.map +1 -1
  12. package/dist/http.mjs +182 -180
  13. package/dist/http.mjs.map +1 -1
  14. package/dist/scripts/postinstall.js.map +1 -1
  15. package/dist/scripts/postinstall.mjs.map +1 -1
  16. package/dist/server.js +5 -5
  17. package/dist/server.mjs +1 -1
  18. package/package.json +4 -3
  19. package/src/http/interceptor/HttpInterceptorClient.ts +13 -7
  20. package/src/http/interceptor/HttpInterceptorStore.ts +4 -6
  21. package/src/http/interceptor/LocalHttpInterceptor.ts +6 -7
  22. package/src/http/interceptor/RemoteHttpInterceptor.ts +7 -11
  23. package/src/http/interceptor/types/options.ts +1 -1
  24. package/src/http/interceptor/types/requests.ts +1 -2
  25. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +4 -5
  26. package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +5 -5
  27. package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +8 -8
  28. package/src/http/interceptorWorker/types/options.ts +1 -3
  29. package/src/http/interceptorWorker/types/requests.ts +1 -2
  30. package/src/http/requestHandler/HttpRequestHandlerClient.ts +3 -2
  31. package/src/http/requestHandler/LocalHttpRequestHandler.ts +1 -2
  32. package/src/http/requestHandler/RemoteHttpRequestHandler.ts +1 -2
  33. package/src/http/requestHandler/errors/TimesCheckError.ts +2 -2
  34. package/src/http/requestHandler/types/public.ts +1 -2
  35. package/src/http/requestHandler/types/requests.ts +1 -2
  36. package/src/http/requestHandler/types/restrictions.ts +1 -2
  37. package/src/server/InterceptorServer.ts +6 -4
  38. package/src/utils/console.ts +3 -8
  39. package/src/utils/crypto.ts +1 -1
  40. package/src/utils/data.ts +0 -20
  41. package/src/utils/fetch.ts +0 -20
  42. package/src/utils/files.ts +5 -18
  43. package/src/utils/processes.ts +1 -1
  44. package/src/webSocket/WebSocketClient.ts +3 -5
  45. package/src/webSocket/WebSocketHandler.ts +1 -1
  46. package/src/webSocket/types.ts +1 -2
  47. package/dist/chunk-3XWHITKR.mjs.map +0 -1
  48. package/dist/chunk-SWLQ2IF6.js.map +0 -1
  49. package/src/types/arrays.d.ts +0 -4
  50. package/src/types/objects.d.ts +0 -14
  51. package/src/types/strings.d.ts +0 -9
  52. package/src/types/utils.ts +0 -28
  53. package/src/utils/imports.ts +0 -12
  54. package/src/utils/time.ts +0 -5
  55. package/src/utils/urls.ts +0 -138
@@ -12,6 +12,41 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
  var chalk2__default = /*#__PURE__*/_interopDefault(chalk2);
13
13
  var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
14
14
 
15
+ // ../zimic-utils/dist/chunk-PAWJFY3S.mjs
16
+ var __defProp = Object.defineProperty;
17
+ var __name2 = /* @__PURE__ */ chunkWCQVDF3K_js.__name((target, value) => __defProp(target, "name", { value, configurable: true }), "__name");
18
+
19
+ // ../zimic-utils/dist/chunk-7MZYQWWC.mjs
20
+ var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
21
+ function createRegExpFromURL(url) {
22
+ URL_PATH_PARAM_REGEX.lastIndex = 0;
23
+ const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
24
+ return new RegExp(`^${urlWithReplacedPathParams}$`);
25
+ }
26
+ chunkWCQVDF3K_js.__name(createRegExpFromURL, "createRegExpFromURL");
27
+ __name2(createRegExpFromURL, "createRegExpFromURL");
28
+ var createRegExpFromURL_default = createRegExpFromURL;
29
+
30
+ // ../zimic-utils/dist/url/excludeURLParams.mjs
31
+ function excludeURLParams(url) {
32
+ url.hash = "";
33
+ url.search = "";
34
+ url.username = "";
35
+ url.password = "";
36
+ return url;
37
+ }
38
+ chunkWCQVDF3K_js.__name(excludeURLParams, "excludeURLParams");
39
+ __name2(excludeURLParams, "excludeURLParams");
40
+ var excludeURLParams_default = excludeURLParams;
41
+
42
+ // ../zimic-utils/dist/chunk-3O5CS47X.mjs
43
+ function isDefined(value) {
44
+ return value !== undefined && value !== null;
45
+ }
46
+ chunkWCQVDF3K_js.__name(isDefined, "isDefined");
47
+ __name2(isDefined, "isDefined");
48
+ var isDefined_default = isDefined;
49
+
15
50
  // src/utils/arrays.ts
16
51
  function removeArrayIndex(array, index) {
17
52
  if (index >= 0 && index < array.length) {
@@ -26,42 +61,36 @@ function removeArrayElement(array, element) {
26
61
  }
27
62
  chunkWCQVDF3K_js.__name(removeArrayElement, "removeArrayElement");
28
63
 
29
- // src/utils/environment.ts
30
- function isClientSide() {
31
- return typeof window !== "undefined";
32
- }
33
- chunkWCQVDF3K_js.__name(isClientSide, "isClientSide");
34
-
35
- // src/utils/imports.ts
64
+ // ../zimic-utils/dist/import/createCachedDynamicImport.mjs
36
65
  function createCachedDynamicImport(importModuleDynamically) {
37
66
  let cachedImportResult;
38
- return /* @__PURE__ */ chunkWCQVDF3K_js.__name(async function importModuleDynamicallyWithCache() {
67
+ return /* @__PURE__ */ __name2(/* @__PURE__ */ chunkWCQVDF3K_js.__name(async function importModuleDynamicallyWithCache() {
39
68
  if (cachedImportResult === undefined) {
40
69
  cachedImportResult = await importModuleDynamically();
41
70
  }
42
71
  return cachedImportResult;
43
- }, "importModuleDynamicallyWithCache");
72
+ }, "importModuleDynamicallyWithCache"), "importModuleDynamicallyWithCache");
44
73
  }
45
74
  chunkWCQVDF3K_js.__name(createCachedDynamicImport, "createCachedDynamicImport");
75
+ __name2(createCachedDynamicImport, "createCachedDynamicImport");
76
+ var createCachedDynamicImport_default = createCachedDynamicImport;
77
+
78
+ // src/utils/environment.ts
79
+ function isClientSide() {
80
+ return typeof window !== "undefined";
81
+ }
82
+ chunkWCQVDF3K_js.__name(isClientSide, "isClientSide");
46
83
 
47
84
  // src/utils/files.ts
48
- var importBuffer = createCachedDynamicImport(
85
+ var importFile = createCachedDynamicImport_default(
49
86
  /* istanbul ignore next -- @preserve
50
- * Ignoring as Node.js >=20 provides a global file and the buffer import won't run. */
51
- () => import('buffer')
87
+ * Ignoring as Node.js >=20 provides a global File and the import fallback won't run. */
88
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
89
+ async () => globalThis.File ?? (await import('buffer')).File
52
90
  );
53
- var FileSingleton;
54
- async function importFile() {
55
- if (FileSingleton) {
56
- return FileSingleton;
57
- }
58
- FileSingleton = globalThis.File ?? (await importBuffer()).File;
59
- return FileSingleton;
60
- }
61
- chunkWCQVDF3K_js.__name(importFile, "importFile");
62
91
 
63
92
  // src/utils/console.ts
64
- var importUtil = createCachedDynamicImport(() => import('util'));
93
+ var importUtil = createCachedDynamicImport_default(() => import('util'));
65
94
  async function formatValueToLog(value, options = {}) {
66
95
  if (isClientSide()) {
67
96
  return value;
@@ -82,40 +111,9 @@ chunkWCQVDF3K_js.__name(formatValueToLog, "formatValueToLog");
82
111
  function logWithPrefix(messageOrMessages, options = {}) {
83
112
  const { method = "log" } = options;
84
113
  const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
85
- console[method](chalk2__default.default.cyan("[zimic]"), ...messages);
114
+ console[method](chalk2__default.default.cyan("[@zimic/interceptor]"), ...messages);
86
115
  }
87
116
  chunkWCQVDF3K_js.__name(logWithPrefix, "logWithPrefix");
88
-
89
- // src/utils/data.ts
90
- function convertArrayBufferToBase64(buffer) {
91
- if (isClientSide()) {
92
- const bufferBytes = new Uint8Array(buffer);
93
- const bufferAsStringArray = [];
94
- for (const byte of bufferBytes) {
95
- const byteCode = String.fromCharCode(byte);
96
- bufferAsStringArray.push(byteCode);
97
- }
98
- const bufferAsString = bufferAsStringArray.join("");
99
- return btoa(bufferAsString);
100
- } else {
101
- return Buffer.from(buffer).toString("base64");
102
- }
103
- }
104
- chunkWCQVDF3K_js.__name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
105
- function convertBase64ToArrayBuffer(base64Value) {
106
- if (isClientSide()) {
107
- const bufferAsString = atob(base64Value);
108
- const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
109
- return array.buffer;
110
- } else {
111
- return Buffer.from(base64Value, "base64");
112
- }
113
- }
114
- chunkWCQVDF3K_js.__name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
115
- function isDefined(value) {
116
- return value !== undefined && value !== null;
117
- }
118
- chunkWCQVDF3K_js.__name(isDefined, "isDefined");
119
117
  var HttpServerTimeoutError = class extends Error {
120
118
  static {
121
119
  chunkWCQVDF3K_js.__name(this, "HttpServerTimeoutError");
@@ -200,105 +198,6 @@ function methodCanHaveResponseBody(method) {
200
198
  }
201
199
  chunkWCQVDF3K_js.__name(methodCanHaveResponseBody, "methodCanHaveResponseBody");
202
200
 
203
- // src/utils/urls.ts
204
- var InvalidURLError = class extends TypeError {
205
- static {
206
- chunkWCQVDF3K_js.__name(this, "InvalidURLError");
207
- }
208
- constructor(url) {
209
- super(`Invalid URL: '${url}'`);
210
- this.name = "InvalidURL";
211
- }
212
- };
213
- var UnsupportedURLProtocolError = class extends TypeError {
214
- static {
215
- chunkWCQVDF3K_js.__name(this, "UnsupportedURLProtocolError");
216
- }
217
- constructor(protocol, availableProtocols) {
218
- super(
219
- `Unsupported URL protocol: '${protocol}'. The available options are ${availableProtocols.map((protocol2) => `'${protocol2}'`).join(", ")}`
220
- );
221
- this.name = "UnsupportedURLProtocolError";
222
- }
223
- };
224
- function createURLOrThrow(rawURL) {
225
- try {
226
- const url = new URL(rawURL);
227
- Object.defineProperty(url, "raw", {
228
- value: rawURL.toString(),
229
- writable: false,
230
- enumerable: true,
231
- configurable: false
232
- });
233
- return url;
234
- } catch {
235
- throw new InvalidURLError(rawURL);
236
- }
237
- }
238
- chunkWCQVDF3K_js.__name(createURLOrThrow, "createURLOrThrow");
239
- function excludeNonPathParams(url) {
240
- url.hash = "";
241
- url.search = "";
242
- url.username = "";
243
- url.password = "";
244
- return url;
245
- }
246
- chunkWCQVDF3K_js.__name(excludeNonPathParams, "excludeNonPathParams");
247
- var DuplicatedPathParamError = class extends Error {
248
- static {
249
- chunkWCQVDF3K_js.__name(this, "DuplicatedPathParamError");
250
- }
251
- constructor(url, paramName) {
252
- super(
253
- `The path parameter '${paramName}' appears more than once in the URL '${url}'. This is not supported. Please make sure that each parameter is unique.`
254
- );
255
- this.name = "DuplicatedPathParamError";
256
- }
257
- };
258
- var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
259
- function ensureUniquePathParams(url) {
260
- const matches = url.matchAll(URL_PATH_PARAM_REGEX);
261
- const uniqueParamNames = /* @__PURE__ */ new Set();
262
- for (const match of matches) {
263
- const paramName = match[1];
264
- if (uniqueParamNames.has(paramName)) {
265
- throw new DuplicatedPathParamError(url, paramName);
266
- }
267
- uniqueParamNames.add(paramName);
268
- }
269
- }
270
- chunkWCQVDF3K_js.__name(ensureUniquePathParams, "ensureUniquePathParams");
271
- function createURL(rawURL, options = {}) {
272
- const {
273
- protocols,
274
- excludeNonPathParams: shouldExcludeNonPathParams = false,
275
- ensureUniquePathParams: shouldEnsureUniquePathParams = false
276
- } = options;
277
- const url = createURLOrThrow(rawURL);
278
- const protocol = url.protocol.replace(/:$/, "");
279
- if (protocols && !protocols.includes(protocol)) {
280
- throw new UnsupportedURLProtocolError(protocol, protocols);
281
- }
282
- if (shouldExcludeNonPathParams) {
283
- excludeNonPathParams(url);
284
- }
285
- if (shouldEnsureUniquePathParams) {
286
- ensureUniquePathParams(url.toString());
287
- }
288
- return url;
289
- }
290
- chunkWCQVDF3K_js.__name(createURL, "createURL");
291
- function prepareURLForRegex(url) {
292
- const encodedURL = encodeURI(url);
293
- return encodedURL.replace(/([.()*?+$\\])/g, "\\$1");
294
- }
295
- chunkWCQVDF3K_js.__name(prepareURLForRegex, "prepareURLForRegex");
296
- function createRegexFromURL(url) {
297
- const urlWithReplacedPathParams = prepareURLForRegex(url).replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
298
- return new RegExp(`^${urlWithReplacedPathParams}$`);
299
- }
300
- chunkWCQVDF3K_js.__name(createRegexFromURL, "createRegexFromURL");
301
-
302
201
  // src/http/requestHandler/types/requests.ts
303
202
  var HTTP_INTERCEPTOR_REQUEST_HIDDEN_PROPERTIES = Object.freeze(
304
203
  /* @__PURE__ */ new Set([
@@ -468,7 +367,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
468
367
  this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor)
469
368
  ]);
470
369
  const candidatesOrPromises = [interceptorStrategy, defaultStrategy, globalDefaultStrategy];
471
- const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined));
370
+ const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined_default));
472
371
  return candidateStrategies;
473
372
  } catch (error) {
474
373
  console.error(error);
@@ -484,7 +383,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
484
383
  }
485
384
  findInterceptorByRequestBaseURL(request) {
486
385
  const interceptor = this.runningInterceptors.findLast((interceptor2) => {
487
- const baseURL = interceptor2.baseURL().toString();
386
+ const baseURL = interceptor2.baseURL();
488
387
  return request.url.startsWith(baseURL);
489
388
  });
490
389
  return interceptor;
@@ -531,7 +430,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
531
430
  const parsedBody = await this.parseRawBody(rawRequest);
532
431
  const headers = new http.HttpHeaders(rawRequest.headers);
533
432
  const pathParams = options.urlRegex ? this.parseRawPathParams(options.urlRegex, rawRequest) : {};
534
- const parsedURL = createURL(rawRequest.url);
433
+ const parsedURL = new URL(rawRequest.url);
535
434
  const searchParams = new http.HttpSearchParams(parsedURL.searchParams);
536
435
  const parsedRequest = new Proxy(rawRequest, {
537
436
  has(target, property) {
@@ -732,6 +631,33 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
732
631
  };
733
632
  var HttpInterceptorWorker_default = HttpInterceptorWorker;
734
633
 
634
+ // src/utils/data.ts
635
+ function convertArrayBufferToBase64(buffer) {
636
+ if (isClientSide()) {
637
+ const bufferBytes = new Uint8Array(buffer);
638
+ const bufferAsStringArray = [];
639
+ for (const byte of bufferBytes) {
640
+ const byteCode = String.fromCharCode(byte);
641
+ bufferAsStringArray.push(byteCode);
642
+ }
643
+ const bufferAsString = bufferAsStringArray.join("");
644
+ return btoa(bufferAsString);
645
+ } else {
646
+ return Buffer.from(buffer).toString("base64");
647
+ }
648
+ }
649
+ chunkWCQVDF3K_js.__name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
650
+ function convertBase64ToArrayBuffer(base64Value) {
651
+ if (isClientSide()) {
652
+ const bufferAsString = atob(base64Value);
653
+ const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
654
+ return array.buffer;
655
+ } else {
656
+ return Buffer.from(base64Value, "base64");
657
+ }
658
+ }
659
+ chunkWCQVDF3K_js.__name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
660
+
735
661
  // src/utils/fetch.ts
736
662
  async function serializeRequest(request) {
737
663
  const requestClone = request.clone();
@@ -884,7 +810,7 @@ async function closeServerSocket(socket, options = {}) {
884
810
  chunkWCQVDF3K_js.__name(closeServerSocket, "closeServerSocket");
885
811
 
886
812
  // src/utils/crypto.ts
887
- var importCrypto = createCachedDynamicImport(async () => {
813
+ var importCrypto = createCachedDynamicImport_default(async () => {
888
814
  const globalCrypto = globalThis.crypto;
889
815
  return globalCrypto ?? await import('crypto');
890
816
  });
@@ -1364,12 +1290,13 @@ var InterceptorServer = class {
1364
1290
  }, "resetWorker");
1365
1291
  registerHttpHandler({ id, url, method }, socket) {
1366
1292
  const handlerGroups = this.httpHandlerGroups[method];
1367
- const fullURL = createURL(url.full, { excludeNonPathParams: true });
1293
+ const fullURL = new URL(url.full);
1294
+ excludeURLParams_default(fullURL);
1368
1295
  handlerGroups.push({
1369
1296
  id,
1370
1297
  url: {
1371
1298
  base: url.base,
1372
- fullRegex: createRegexFromURL(fullURL.toString())
1299
+ fullRegex: createRegExpFromURL_default(fullURL.toString())
1373
1300
  },
1374
1301
  socket
1375
1302
  });
@@ -1443,7 +1370,7 @@ var InterceptorServer = class {
1443
1370
  async createResponseForRequest(request) {
1444
1371
  const webSocketServer = this.webSocketServer();
1445
1372
  const methodHandlers = this.httpHandlerGroups[request.method];
1446
- const requestURL = createURL(request.url, { excludeNonPathParams: true }).toString();
1373
+ const requestURL = excludeURLParams_default(new URL(request.url)).toString();
1447
1374
  let matchedSomeInterceptor = false;
1448
1375
  for (let index = methodHandlers.length - 1; index >= 0; index--) {
1449
1376
  const handler = methodHandlers[index];
@@ -1535,8 +1462,6 @@ var InterceptorServerNamespace_default = InterceptorServerNamespace;
1535
1462
 
1536
1463
  // src/server/index.ts
1537
1464
  var interceptorServer = Object.freeze(new InterceptorServerNamespace_default());
1538
- /* istanbul ignore next -- @preserve
1539
- * Ignoring as Node.js >=20 provides a global File and the import fallback won't run. */
1540
1465
  /* istanbul ignore if -- @preserve
1541
1466
  * This is expected not to happen since the servers are not stopped unless they are running. */
1542
1467
  /* istanbul ignore if -- @preserve
@@ -1566,8 +1491,8 @@ var interceptorServer = Object.freeze(new InterceptorServerNamespace_default());
1566
1491
  exports.DEFAULT_ACCESS_CONTROL_HEADERS = DEFAULT_ACCESS_CONTROL_HEADERS;
1567
1492
  exports.DEFAULT_PREFLIGHT_STATUS_CODE = DEFAULT_PREFLIGHT_STATUS_CODE;
1568
1493
  exports.NotStartedInterceptorServerError_default = NotStartedInterceptorServerError_default;
1569
- exports.createCachedDynamicImport = createCachedDynamicImport;
1494
+ exports.createCachedDynamicImport_default = createCachedDynamicImport_default;
1570
1495
  exports.interceptorServer = interceptorServer;
1571
1496
  exports.logWithPrefix = logWithPrefix;
1572
- //# sourceMappingURL=chunk-SWLQ2IF6.js.map
1573
- //# sourceMappingURL=chunk-SWLQ2IF6.js.map
1497
+ //# sourceMappingURL=chunk-JIUQ7G6N.js.map
1498
+ //# sourceMappingURL=chunk-JIUQ7G6N.js.map