@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
package/dist/http.mjs CHANGED
@@ -22,168 +22,62 @@ var UnknownHttpInterceptorTypeError = class extends TypeError {
22
22
  };
23
23
  var UnknownHttpInterceptorTypeError_default = UnknownHttpInterceptorTypeError;
24
24
 
25
- // src/utils/urls.ts
26
- var InvalidURLError = class extends TypeError {
27
- static {
28
- __name(this, "InvalidURLError");
29
- }
30
- constructor(url) {
31
- super(`Invalid URL: '${url}'`);
32
- this.name = "InvalidURL";
33
- }
34
- };
35
- var UnsupportedURLProtocolError = class extends TypeError {
36
- static {
37
- __name(this, "UnsupportedURLProtocolError");
38
- }
39
- constructor(protocol, availableProtocols) {
40
- super(
41
- `Unsupported URL protocol: '${protocol}'. The available options are ${availableProtocols.map((protocol2) => `'${protocol2}'`).join(", ")}`
42
- );
43
- this.name = "UnsupportedURLProtocolError";
44
- }
45
- };
46
- function createURLOrThrow(rawURL) {
47
- try {
48
- const url = new URL(rawURL);
49
- Object.defineProperty(url, "raw", {
50
- value: rawURL.toString(),
51
- writable: false,
52
- enumerable: true,
53
- configurable: false
54
- });
55
- return url;
56
- } catch {
57
- throw new InvalidURLError(rawURL);
58
- }
59
- }
60
- __name(createURLOrThrow, "createURLOrThrow");
61
- function excludeNonPathParams(url) {
25
+ // ../zimic-utils/dist/chunk-PAWJFY3S.mjs
26
+ var __defProp2 = Object.defineProperty;
27
+ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
28
+
29
+ // ../zimic-utils/dist/url/excludeURLParams.mjs
30
+ function excludeURLParams(url) {
62
31
  url.hash = "";
63
32
  url.search = "";
64
33
  url.username = "";
65
34
  url.password = "";
66
35
  return url;
67
36
  }
68
- __name(excludeNonPathParams, "excludeNonPathParams");
69
- var DuplicatedPathParamError = class extends Error {
37
+ __name(excludeURLParams, "excludeURLParams");
38
+ __name2(excludeURLParams, "excludeURLParams");
39
+ var excludeURLParams_default = excludeURLParams;
40
+
41
+ // ../zimic-utils/dist/url/validateURLProtocol.mjs
42
+ var UnsupportedURLProtocolError = class extends TypeError {
70
43
  static {
71
- __name(this, "DuplicatedPathParamError");
44
+ __name(this, "UnsupportedURLProtocolError");
72
45
  }
73
- constructor(url, paramName) {
46
+ static {
47
+ __name2(this, "UnsupportedURLProtocolError");
48
+ }
49
+ constructor(protocol, availableProtocols) {
74
50
  super(
75
- `The path parameter '${paramName}' appears more than once in the URL '${url}'. This is not supported. Please make sure that each parameter is unique.`
51
+ `Unsupported URL protocol: '${protocol}'. The available options are ${availableProtocols.map((protocol2) => `'${protocol2}'`).join(", ")}`
76
52
  );
77
- this.name = "DuplicatedPathParamError";
53
+ this.name = "UnsupportedURLProtocolError";
78
54
  }
79
55
  };
80
- var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
81
- function ensureUniquePathParams(url) {
82
- const matches = url.matchAll(URL_PATH_PARAM_REGEX);
83
- const uniqueParamNames = /* @__PURE__ */ new Set();
84
- for (const match of matches) {
85
- const paramName = match[1];
86
- if (uniqueParamNames.has(paramName)) {
87
- throw new DuplicatedPathParamError(url, paramName);
88
- }
89
- uniqueParamNames.add(paramName);
90
- }
91
- }
92
- __name(ensureUniquePathParams, "ensureUniquePathParams");
93
- function createURL(rawURL, options = {}) {
94
- const {
95
- protocols,
96
- excludeNonPathParams: shouldExcludeNonPathParams = false,
97
- ensureUniquePathParams: shouldEnsureUniquePathParams = false
98
- } = options;
99
- const url = createURLOrThrow(rawURL);
56
+ function validateURLProtocol(url, protocols) {
100
57
  const protocol = url.protocol.replace(/:$/, "");
101
- if (protocols && !protocols.includes(protocol)) {
58
+ if (!protocols.includes(protocol)) {
102
59
  throw new UnsupportedURLProtocolError(protocol, protocols);
103
60
  }
104
- if (shouldExcludeNonPathParams) {
105
- excludeNonPathParams(url);
106
- }
107
- if (shouldEnsureUniquePathParams) {
108
- ensureUniquePathParams(url.toString());
109
- }
110
- return url;
111
- }
112
- __name(createURL, "createURL");
113
- function prepareURLForRegex(url) {
114
- const encodedURL = encodeURI(url);
115
- return encodedURL.replace(/([.()*?+$\\])/g, "\\$1");
116
- }
117
- __name(prepareURLForRegex, "prepareURLForRegex");
118
- function createRegexFromURL(url) {
119
- const urlWithReplacedPathParams = prepareURLForRegex(url).replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
120
- return new RegExp(`^${urlWithReplacedPathParams}$`);
121
61
  }
122
- __name(createRegexFromURL, "createRegexFromURL");
123
- function joinURL(...parts) {
124
- return parts.map((part, index) => {
125
- const isFirstPart = index === 0;
126
- const isLastPart = index === parts.length - 1;
127
- let partAsString = part.toString();
128
- if (!isFirstPart) {
129
- partAsString = partAsString.replace(/^\//, "");
130
- }
131
- if (!isLastPart) {
132
- partAsString = partAsString.replace(/\/$/, "");
133
- }
134
- return partAsString;
135
- }).filter((part) => part.length > 0).join("/");
136
- }
137
- __name(joinURL, "joinURL");
62
+ __name(validateURLProtocol, "validateURLProtocol");
63
+ __name2(validateURLProtocol, "validateURLProtocol");
64
+ var validateURLProtocol_default = validateURLProtocol;
138
65
 
139
- // src/utils/environment.ts
140
- function isClientSide() {
141
- return typeof window !== "undefined";
66
+ // ../zimic-utils/dist/data/blobContains.mjs
67
+ async function blobContains(blob, otherBlob) {
68
+ return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
142
69
  }
143
- __name(isClientSide, "isClientSide");
70
+ __name(blobContains, "blobContains");
71
+ __name2(blobContains, "blobContains");
72
+ var blobContains_default = blobContains;
144
73
 
145
- // src/utils/data.ts
74
+ // ../zimic-utils/dist/chunk-HVLEF6VF.mjs
146
75
  async function blobEquals(blob, otherBlob) {
147
76
  return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
148
77
  }
149
78
  __name(blobEquals, "blobEquals");
150
- async function blobContains(blob, otherBlob) {
151
- return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
152
- }
153
- __name(blobContains, "blobContains");
154
- function convertArrayBufferToBase64(buffer) {
155
- if (isClientSide()) {
156
- const bufferBytes = new Uint8Array(buffer);
157
- const bufferAsStringArray = [];
158
- for (const byte of bufferBytes) {
159
- const byteCode = String.fromCharCode(byte);
160
- bufferAsStringArray.push(byteCode);
161
- }
162
- const bufferAsString = bufferAsStringArray.join("");
163
- return btoa(bufferAsString);
164
- } else {
165
- return Buffer.from(buffer).toString("base64");
166
- }
167
- }
168
- __name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
169
- function convertBase64ToArrayBuffer(base64Value) {
170
- if (isClientSide()) {
171
- const bufferAsString = atob(base64Value);
172
- const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
173
- return array.buffer;
174
- } else {
175
- return Buffer.from(base64Value, "base64");
176
- }
177
- }
178
- __name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
179
- function isDefined(value) {
180
- return value !== undefined && value !== null;
181
- }
182
- __name(isDefined, "isDefined");
183
- function isNonEmpty(value) {
184
- return isDefined(value) && value !== "";
185
- }
186
- __name(isNonEmpty, "isNonEmpty");
79
+ __name2(blobEquals, "blobEquals");
80
+ var blobEquals_default = blobEquals;
187
81
 
188
82
  // src/utils/json.ts
189
83
  function isPrimitiveJSONValue(value) {
@@ -288,17 +182,41 @@ var NoResponseDefinitionError = class extends TypeError {
288
182
  };
289
183
  var NoResponseDefinitionError_default = NoResponseDefinitionError;
290
184
 
291
- // src/utils/imports.ts
185
+ // ../zimic-utils/dist/chunk-3O5CS47X.mjs
186
+ function isDefined(value) {
187
+ return value !== undefined && value !== null;
188
+ }
189
+ __name(isDefined, "isDefined");
190
+ __name2(isDefined, "isDefined");
191
+ var isDefined_default = isDefined;
192
+
193
+ // ../zimic-utils/dist/data/isNonEmpty.mjs
194
+ function isNonEmpty(value) {
195
+ return isDefined_default(value) && value !== "";
196
+ }
197
+ __name(isNonEmpty, "isNonEmpty");
198
+ __name2(isNonEmpty, "isNonEmpty");
199
+ var isNonEmpty_default = isNonEmpty;
200
+
201
+ // ../zimic-utils/dist/import/createCachedDynamicImport.mjs
292
202
  function createCachedDynamicImport(importModuleDynamically) {
293
203
  let cachedImportResult;
294
- return /* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
204
+ return /* @__PURE__ */ __name2(/* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
295
205
  if (cachedImportResult === undefined) {
296
206
  cachedImportResult = await importModuleDynamically();
297
207
  }
298
208
  return cachedImportResult;
299
- }, "importModuleDynamicallyWithCache");
209
+ }, "importModuleDynamicallyWithCache"), "importModuleDynamicallyWithCache");
300
210
  }
301
211
  __name(createCachedDynamicImport, "createCachedDynamicImport");
212
+ __name2(createCachedDynamicImport, "createCachedDynamicImport");
213
+ var createCachedDynamicImport_default = createCachedDynamicImport;
214
+
215
+ // src/utils/environment.ts
216
+ function isClientSide() {
217
+ return typeof window !== "undefined";
218
+ }
219
+ __name(isClientSide, "isClientSide");
302
220
  function isGlobalFileAvailable() {
303
221
  return globalThis.File !== undefined;
304
222
  }
@@ -341,7 +259,7 @@ function stringifyValueToLog(value, options = {}) {
341
259
  return fallback(value);
342
260
  }
343
261
  __name(stringifyValueToLog, "stringifyValueToLog");
344
- var importUtil = createCachedDynamicImport(() => import('util'));
262
+ var importUtil = createCachedDynamicImport_default(() => import('util'));
345
263
  async function formatValueToLog(value, options = {}) {
346
264
  if (isClientSide()) {
347
265
  return value;
@@ -362,7 +280,7 @@ __name(formatValueToLog, "formatValueToLog");
362
280
  function logWithPrefix(messageOrMessages, options = {}) {
363
281
  const { method = "log" } = options;
364
282
  const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
365
- console[method](chalk2.cyan("[zimic]"), ...messages);
283
+ console[method](chalk2.cyan("[@zimic/interceptor]"), ...messages);
366
284
  }
367
285
  __name(logWithPrefix, "logWithPrefix");
368
286
 
@@ -444,7 +362,7 @@ function createMessage(options) {
444
362
  const messageHeader = createMessageHeader(options);
445
363
  const messageDiffs = createMessageDiffs(options);
446
364
  const messageFooter = createMessageFooter();
447
- return [messageHeader, messageDiffs, messageFooter].filter(isNonEmpty).join("\n\n");
365
+ return [messageHeader, messageDiffs, messageFooter].filter(isNonEmpty_default).join("\n\n");
448
366
  }
449
367
  __name(createMessage, "createMessage");
450
368
  var TimesCheckError = class extends TypeError {
@@ -669,7 +587,7 @@ var HttpRequestHandlerClient = class {
669
587
  diff: { expected: restrictionBody, received: body }
670
588
  };
671
589
  }
672
- const matchesRestriction2 = restriction.exact ? await blobEquals(body, restrictionBody) : await blobContains(body, restrictionBody);
590
+ const matchesRestriction2 = restriction.exact ? await blobEquals_default(body, restrictionBody) : await blobContains_default(body, restrictionBody);
673
591
  return matchesRestriction2 ? { value: true } : {
674
592
  value: false,
675
593
  diff: { expected: restrictionBody, received: body }
@@ -770,6 +688,36 @@ var LocalHttpRequestHandler = class {
770
688
  };
771
689
  var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
772
690
 
691
+ // ../zimic-utils/dist/chunk-7MZYQWWC.mjs
692
+ var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
693
+ function createRegExpFromURL(url) {
694
+ URL_PATH_PARAM_REGEX.lastIndex = 0;
695
+ const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
696
+ return new RegExp(`^${urlWithReplacedPathParams}$`);
697
+ }
698
+ __name(createRegExpFromURL, "createRegExpFromURL");
699
+ __name2(createRegExpFromURL, "createRegExpFromURL");
700
+ var createRegExpFromURL_default = createRegExpFromURL;
701
+
702
+ // ../zimic-utils/dist/url/joinURL.mjs
703
+ function joinURL(...parts) {
704
+ return parts.map((part, index) => {
705
+ const isFirstPart = index === 0;
706
+ const isLastPart = index === parts.length - 1;
707
+ let partAsString = part.toString();
708
+ if (!isFirstPart) {
709
+ partAsString = partAsString.replace(/^\//, "");
710
+ }
711
+ if (!isLastPart) {
712
+ partAsString = partAsString.replace(/\/$/, "");
713
+ }
714
+ return partAsString;
715
+ }).filter((part) => part.length > 0).join("/");
716
+ }
717
+ __name(joinURL, "joinURL");
718
+ __name2(joinURL, "joinURL");
719
+ var joinURL_default = joinURL;
720
+
773
721
  // src/utils/arrays.ts
774
722
  function removeArrayIndex(array, index) {
775
723
  if (index >= 0 && index < array.length) {
@@ -958,7 +906,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
958
906
  this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor)
959
907
  ]);
960
908
  const candidatesOrPromises = [interceptorStrategy, defaultStrategy, globalDefaultStrategy];
961
- const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined));
909
+ const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined_default));
962
910
  return candidateStrategies;
963
911
  } catch (error) {
964
912
  console.error(error);
@@ -974,7 +922,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
974
922
  }
975
923
  findInterceptorByRequestBaseURL(request) {
976
924
  const interceptor = this.runningInterceptors.findLast((interceptor2) => {
977
- const baseURL = interceptor2.baseURL().toString();
925
+ const baseURL = interceptor2.baseURL();
978
926
  return request.url.startsWith(baseURL);
979
927
  });
980
928
  return interceptor;
@@ -1021,7 +969,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
1021
969
  const parsedBody = await this.parseRawBody(rawRequest);
1022
970
  const headers = new HttpHeaders(rawRequest.headers);
1023
971
  const pathParams = options.urlRegex ? this.parseRawPathParams(options.urlRegex, rawRequest) : {};
1024
- const parsedURL = createURL(rawRequest.url);
972
+ const parsedURL = new URL(rawRequest.url);
1025
973
  const searchParams = new HttpSearchParams(parsedURL.searchParams);
1026
974
  const parsedRequest = new Proxy(rawRequest, {
1027
975
  has(target, property) {
@@ -1222,6 +1170,37 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
1222
1170
  };
1223
1171
  var HttpInterceptorWorker_default = HttpInterceptorWorker;
1224
1172
 
1173
+ // ../zimic-utils/dist/url/validateURLPathParams.mjs
1174
+ var DuplicatedPathParamError = class extends Error {
1175
+ static {
1176
+ __name(this, "DuplicatedPathParamError");
1177
+ }
1178
+ static {
1179
+ __name2(this, "DuplicatedPathParamError");
1180
+ }
1181
+ constructor(url, paramName) {
1182
+ super(
1183
+ `The path parameter '${paramName}' appears more than once in the URL '${url.toString()}'. This is not supported. Please make sure that each parameter is unique.`
1184
+ );
1185
+ this.name = "DuplicatedPathParamError";
1186
+ }
1187
+ };
1188
+ function validateURLPathParams(url) {
1189
+ URL_PATH_PARAM_REGEX.lastIndex = 0;
1190
+ const matches = url.toString().matchAll(URL_PATH_PARAM_REGEX);
1191
+ const uniqueParamNames = /* @__PURE__ */ new Set();
1192
+ for (const match of matches) {
1193
+ const paramName = match[1];
1194
+ if (uniqueParamNames.has(paramName)) {
1195
+ throw new DuplicatedPathParamError(url, paramName);
1196
+ }
1197
+ uniqueParamNames.add(paramName);
1198
+ }
1199
+ }
1200
+ __name(validateURLPathParams, "validateURLPathParams");
1201
+ __name2(validateURLPathParams, "validateURLPathParams");
1202
+ var validateURLPathParams_default = validateURLPathParams;
1203
+
1225
1204
  // src/http/interceptor/errors/NotStartedHttpInterceptorError.ts
1226
1205
  var NotStartedHttpInterceptorError = class extends Error {
1227
1206
  static {
@@ -1373,10 +1352,9 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1373
1352
  use(interceptor, method, rawURL, createResponse) {
1374
1353
  const internalWorker = this.internalWorkerOrThrow();
1375
1354
  const lowercaseMethod = method.toLowerCase();
1376
- const url = createURL(rawURL, {
1377
- excludeNonPathParams: true,
1378
- ensureUniquePathParams: true
1379
- });
1355
+ const url = new URL(rawURL);
1356
+ excludeURLParams_default(url);
1357
+ validateURLPathParams_default(url);
1380
1358
  const httpHandler = http[lowercaseMethod](url.toString(), async (context) => {
1381
1359
  const request = context.request;
1382
1360
  const requestClone = request.clone();
@@ -1573,7 +1551,11 @@ var HttpInterceptorClient = class {
1573
1551
  this._shouldSaveRequests = options.saveRequests ?? false;
1574
1552
  }
1575
1553
  baseURL() {
1576
- return this._baseURL;
1554
+ const baseURL = this._baseURL;
1555
+ if (baseURL.href === `${baseURL.origin}/`) {
1556
+ return baseURL.origin;
1557
+ }
1558
+ return baseURL.toString();
1577
1559
  }
1578
1560
  platform() {
1579
1561
  return this.worker.platform();
@@ -1656,8 +1638,8 @@ var HttpInterceptorClient = class {
1656
1638
  return;
1657
1639
  }
1658
1640
  this.handlerClientsByMethod[handler.method()].set(handler.path(), handlerClients);
1659
- const url = joinURL(this.baseURL(), handler.path());
1660
- const urlRegex = createRegexFromURL(url);
1641
+ const url = joinURL_default(this.baseURL(), handler.path());
1642
+ const urlRegex = createRegExpFromURL_default(url);
1661
1643
  const registrationResult = this.worker.use(this, handler.method(), url, async (context) => {
1662
1644
  const response = await this.handleInterceptedRequest(
1663
1645
  urlRegex,
@@ -1741,11 +1723,38 @@ var HttpInterceptorClient = class {
1741
1723
  var HttpInterceptorClient_default = HttpInterceptorClient;
1742
1724
 
1743
1725
  // src/utils/crypto.ts
1744
- var importCrypto = createCachedDynamicImport(async () => {
1726
+ var importCrypto = createCachedDynamicImport_default(async () => {
1745
1727
  const globalCrypto = globalThis.crypto;
1746
1728
  return globalCrypto ?? await import('crypto');
1747
1729
  });
1748
1730
 
1731
+ // src/utils/data.ts
1732
+ function convertArrayBufferToBase64(buffer) {
1733
+ if (isClientSide()) {
1734
+ const bufferBytes = new Uint8Array(buffer);
1735
+ const bufferAsStringArray = [];
1736
+ for (const byte of bufferBytes) {
1737
+ const byteCode = String.fromCharCode(byte);
1738
+ bufferAsStringArray.push(byteCode);
1739
+ }
1740
+ const bufferAsString = bufferAsStringArray.join("");
1741
+ return btoa(bufferAsString);
1742
+ } else {
1743
+ return Buffer.from(buffer).toString("base64");
1744
+ }
1745
+ }
1746
+ __name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
1747
+ function convertBase64ToArrayBuffer(base64Value) {
1748
+ if (isClientSide()) {
1749
+ const bufferAsString = atob(base64Value);
1750
+ const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
1751
+ return array.buffer;
1752
+ } else {
1753
+ return Buffer.from(base64Value, "base64");
1754
+ }
1755
+ }
1756
+ __name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
1757
+
1749
1758
  // src/utils/fetch.ts
1750
1759
  function deserializeRequest(serializedRequest) {
1751
1760
  const deserializedBody = serializedRequest.body ? convertBase64ToArrayBuffer(serializedRequest.body) : null;
@@ -2159,9 +2168,8 @@ var WebSocketClient = class extends WebSocketHandler_default {
2159
2168
  socketTimeout: options.socketTimeout,
2160
2169
  messageTimeout: options.messageTimeout
2161
2170
  });
2162
- this.url = createURL(options.url, {
2163
- protocols: SUPPORTED_WEB_SOCKET_PROTOCOLS
2164
- });
2171
+ this.url = new URL(options.url);
2172
+ validateURLProtocol_default(this.url, SUPPORTED_WEB_SOCKET_PROTOCOLS);
2165
2173
  }
2166
2174
  isRunning() {
2167
2175
  return this.socket !== undefined && this.socket.readyState === this.socket.OPEN;
@@ -2202,7 +2210,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2202
2210
  });
2203
2211
  }
2204
2212
  deriveWebSocketServerURL(serverURL) {
2205
- const webSocketServerURL = createURL(serverURL);
2213
+ const webSocketServerURL = new URL(serverURL);
2206
2214
  webSocketServerURL.protocol = serverURL.protocol.replace(/^http(s)?:$/, "ws$1:");
2207
2215
  return webSocketServerURL;
2208
2216
  }
@@ -2266,14 +2274,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2266
2274
  throw new NotStartedHttpInterceptorError_default();
2267
2275
  }
2268
2276
  const crypto = await importCrypto();
2269
- const url = createURL(rawURL, {
2270
- excludeNonPathParams: true,
2271
- ensureUniquePathParams: true
2272
- });
2277
+ const url = new URL(rawURL);
2278
+ excludeURLParams_default(url);
2279
+ validateURLPathParams_default(url);
2273
2280
  const handler = {
2274
2281
  id: crypto.randomUUID(),
2275
2282
  url: {
2276
- base: interceptor.baseURL().toString(),
2283
+ base: interceptor.baseURL(),
2277
2284
  full: url.toString()
2278
2285
  },
2279
2286
  method,
@@ -2414,10 +2421,9 @@ var LocalHttpInterceptor = class {
2414
2421
  _client;
2415
2422
  constructor(options) {
2416
2423
  this.type = options.type;
2417
- const baseURL = createURL(options.baseURL, {
2418
- protocols: SUPPORTED_BASE_URL_PROTOCOLS,
2419
- excludeNonPathParams: true
2420
- });
2424
+ const baseURL = new URL(options.baseURL);
2425
+ validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
2426
+ excludeURLParams_default(baseURL);
2421
2427
  const worker = this.store.getOrCreateLocalWorker({});
2422
2428
  this._client = new HttpInterceptorClient_default({
2423
2429
  worker,
@@ -2432,7 +2438,7 @@ var LocalHttpInterceptor = class {
2432
2438
  return this._client;
2433
2439
  }
2434
2440
  baseURL() {
2435
- return this._client.baseURL().raw;
2441
+ return this._client.baseURL();
2436
2442
  }
2437
2443
  platform() {
2438
2444
  return this._client.platform();
@@ -2493,14 +2499,10 @@ var RemoteHttpInterceptor = class {
2493
2499
  _client;
2494
2500
  constructor(options) {
2495
2501
  this.type = options.type;
2496
- const baseURL = createURL(options.baseURL, {
2497
- protocols: SUPPORTED_BASE_URL_PROTOCOLS,
2498
- excludeNonPathParams: true
2499
- });
2500
- const serverURL = createURL(baseURL.origin, {
2501
- protocols: SUPPORTED_BASE_URL_PROTOCOLS,
2502
- excludeNonPathParams: true
2503
- });
2502
+ const baseURL = new URL(options.baseURL);
2503
+ validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
2504
+ excludeURLParams_default(baseURL);
2505
+ const serverURL = new URL(baseURL.origin);
2504
2506
  const worker = this.store.getOrCreateRemoteWorker({ serverURL });
2505
2507
  this._client = new HttpInterceptorClient_default({
2506
2508
  worker,
@@ -2515,7 +2517,7 @@ var RemoteHttpInterceptor = class {
2515
2517
  return this._client;
2516
2518
  }
2517
2519
  baseURL() {
2518
- return this._client.baseURL().raw;
2520
+ return this._client.baseURL();
2519
2521
  }
2520
2522
  platform() {
2521
2523
  return this._client.platform();