@zimic/interceptor 0.14.0-canary.24 → 0.14.0-canary.25
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-BJLJWEVE.js → chunk-3623PRKE.js} +20 -20
- package/dist/chunk-3623PRKE.js.map +1 -0
- package/dist/{chunk-QSY6YMZ7.mjs → chunk-FEGMEAEO.mjs} +20 -20
- package/dist/chunk-FEGMEAEO.mjs.map +1 -0
- package/dist/cli.js +16 -16
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +11 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/http.js +35 -31
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +35 -31
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +5 -5
- package/dist/server.mjs +1 -1
- package/package.json +12 -12
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +3 -3
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +3 -6
- package/src/utils/environment.ts +5 -1
- package/dist/chunk-BJLJWEVE.js.map +0 -1
- package/dist/chunk-QSY6YMZ7.mjs.map +0 -1
package/dist/http.mjs
CHANGED
|
@@ -184,7 +184,7 @@ var NoResponseDefinitionError_default = NoResponseDefinitionError;
|
|
|
184
184
|
|
|
185
185
|
// ../zimic-utils/dist/chunk-3O5CS47X.mjs
|
|
186
186
|
function isDefined(value) {
|
|
187
|
-
return value !==
|
|
187
|
+
return value !== void 0 && value !== null;
|
|
188
188
|
}
|
|
189
189
|
__name(isDefined, "isDefined");
|
|
190
190
|
__name2(isDefined, "isDefined");
|
|
@@ -202,7 +202,7 @@ var isNonEmpty_default = isNonEmpty;
|
|
|
202
202
|
function createCachedDynamicImport(importModuleDynamically) {
|
|
203
203
|
let cachedImportResult;
|
|
204
204
|
return /* @__PURE__ */ __name2(/* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
|
|
205
|
-
if (cachedImportResult ===
|
|
205
|
+
if (cachedImportResult === void 0) {
|
|
206
206
|
cachedImportResult = await importModuleDynamically();
|
|
207
207
|
}
|
|
208
208
|
return cachedImportResult;
|
|
@@ -213,12 +213,16 @@ __name2(createCachedDynamicImport, "createCachedDynamicImport");
|
|
|
213
213
|
var createCachedDynamicImport_default = createCachedDynamicImport;
|
|
214
214
|
|
|
215
215
|
// src/utils/environment.ts
|
|
216
|
+
function isServerSide() {
|
|
217
|
+
return typeof process !== "undefined" && typeof process.versions !== "undefined";
|
|
218
|
+
}
|
|
219
|
+
__name(isServerSide, "isServerSide");
|
|
216
220
|
function isClientSide() {
|
|
217
|
-
return typeof window !== "undefined";
|
|
221
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
218
222
|
}
|
|
219
223
|
__name(isClientSide, "isClientSide");
|
|
220
224
|
function isGlobalFileAvailable() {
|
|
221
|
-
return globalThis.File !==
|
|
225
|
+
return globalThis.File !== void 0;
|
|
222
226
|
}
|
|
223
227
|
__name(isGlobalFileAvailable, "isGlobalFileAvailable");
|
|
224
228
|
|
|
@@ -237,7 +241,7 @@ function stringifyJSONToLog(value) {
|
|
|
237
241
|
__name(stringifyJSONToLog, "stringifyJSONToLog");
|
|
238
242
|
function stringifyValueToLog(value, options = {}) {
|
|
239
243
|
const { fallback = stringifyJSONToLog, includeClassName } = options;
|
|
240
|
-
if (value === null || value ===
|
|
244
|
+
if (value === null || value === void 0 || typeof value !== "object") {
|
|
241
245
|
return String(value);
|
|
242
246
|
}
|
|
243
247
|
if (value instanceof HttpHeaders) {
|
|
@@ -385,7 +389,7 @@ var TimesDeclarationPointer = class extends Error {
|
|
|
385
389
|
}
|
|
386
390
|
constructor(minNumberOfRequests, maxNumberOfRequests) {
|
|
387
391
|
super("declared at:");
|
|
388
|
-
this.name = `handler.times(${minNumberOfRequests}${maxNumberOfRequests ===
|
|
392
|
+
this.name = `handler.times(${minNumberOfRequests}${maxNumberOfRequests === void 0 ? "" : `, ${maxNumberOfRequests}`})`;
|
|
389
393
|
}
|
|
390
394
|
};
|
|
391
395
|
var TimesDeclarationPointer_default = TimesDeclarationPointer;
|
|
@@ -462,15 +466,15 @@ var HttpRequestHandlerClient = class {
|
|
|
462
466
|
this.limits = {
|
|
463
467
|
numberOfRequests: DEFAULT_NUMBER_OF_REQUEST_LIMITS
|
|
464
468
|
};
|
|
465
|
-
this.timesDeclarationPointer =
|
|
469
|
+
this.timesDeclarationPointer = void 0;
|
|
466
470
|
this.numberOfMatchedRequests = 0;
|
|
467
471
|
this.unmatchedRequestGroups.length = 0;
|
|
468
472
|
this.interceptedRequests.length = 0;
|
|
469
|
-
this.createResponseDeclaration =
|
|
473
|
+
this.createResponseDeclaration = void 0;
|
|
470
474
|
return this;
|
|
471
475
|
}
|
|
472
476
|
async matchesRequest(request) {
|
|
473
|
-
const hasDeclaredResponse = this.createResponseDeclaration !==
|
|
477
|
+
const hasDeclaredResponse = this.createResponseDeclaration !== void 0;
|
|
474
478
|
if (!hasDeclaredResponse) {
|
|
475
479
|
return false;
|
|
476
480
|
}
|
|
@@ -478,7 +482,7 @@ var HttpRequestHandlerClient = class {
|
|
|
478
482
|
if (restrictionsMatch.value) {
|
|
479
483
|
this.numberOfMatchedRequests++;
|
|
480
484
|
} else {
|
|
481
|
-
const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests() && this.restrictions.length > 0 && this.timesDeclarationPointer !==
|
|
485
|
+
const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests() && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
|
|
482
486
|
if (shouldSaveUnmatchedGroup) {
|
|
483
487
|
this.unmatchedRequestGroups.push({ request, diff: restrictionsMatch.diff });
|
|
484
488
|
}
|
|
@@ -516,7 +520,7 @@ var HttpRequestHandlerClient = class {
|
|
|
516
520
|
return { value: true };
|
|
517
521
|
}
|
|
518
522
|
matchesRequestHeadersRestrictions(request, restriction) {
|
|
519
|
-
if (restriction.headers ===
|
|
523
|
+
if (restriction.headers === void 0) {
|
|
520
524
|
return { value: true };
|
|
521
525
|
}
|
|
522
526
|
const restrictedHeaders = new HttpHeaders(
|
|
@@ -529,7 +533,7 @@ var HttpRequestHandlerClient = class {
|
|
|
529
533
|
};
|
|
530
534
|
}
|
|
531
535
|
matchesRequestSearchParamsRestrictions(request, restriction) {
|
|
532
|
-
if (restriction.searchParams ===
|
|
536
|
+
if (restriction.searchParams === void 0) {
|
|
533
537
|
return { value: true };
|
|
534
538
|
}
|
|
535
539
|
const restrictedSearchParams = new HttpSearchParams(
|
|
@@ -542,7 +546,7 @@ var HttpRequestHandlerClient = class {
|
|
|
542
546
|
};
|
|
543
547
|
}
|
|
544
548
|
async matchesRequestBodyRestrictions(request, restriction) {
|
|
545
|
-
if (restriction.body ===
|
|
549
|
+
if (restriction.body === void 0) {
|
|
546
550
|
return { value: true };
|
|
547
551
|
}
|
|
548
552
|
const body = request.body;
|
|
@@ -688,12 +692,12 @@ var LocalHttpRequestHandler = class {
|
|
|
688
692
|
};
|
|
689
693
|
var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
|
|
690
694
|
|
|
691
|
-
// ../zimic-utils/dist/chunk-
|
|
695
|
+
// ../zimic-utils/dist/chunk-RIVHLEFF.mjs
|
|
692
696
|
var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
|
|
693
697
|
function createRegExpFromURL(url) {
|
|
694
698
|
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(
|
|
699
|
+
const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/^(\/)|(\/)$/g, "");
|
|
700
|
+
return new RegExp(`^(?:/)?${urlWithReplacedPathParams}(?:/)?$`);
|
|
697
701
|
}
|
|
698
702
|
__name(createRegExpFromURL, "createRegExpFromURL");
|
|
699
703
|
__name2(createRegExpFromURL, "createRegExpFromURL");
|
|
@@ -868,7 +872,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
868
872
|
this.stoppingPromise = stoppingResult;
|
|
869
873
|
await this.stoppingPromise;
|
|
870
874
|
}
|
|
871
|
-
this.stoppingPromise =
|
|
875
|
+
this.stoppingPromise = void 0;
|
|
872
876
|
}
|
|
873
877
|
async logUnhandledRequestIfNecessary(request, strategy) {
|
|
874
878
|
if (strategy?.log) {
|
|
@@ -953,7 +957,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
953
957
|
if (!canHaveBody) {
|
|
954
958
|
return new Response(null, { headers, status });
|
|
955
959
|
}
|
|
956
|
-
if (typeof declaration.body === "string" || declaration.body ===
|
|
960
|
+
if (typeof declaration.body === "string" || declaration.body === void 0 || declaration.body instanceof FormData || declaration.body instanceof URLSearchParams || declaration.body instanceof Blob || declaration.body instanceof ArrayBuffer) {
|
|
957
961
|
return new Response(declaration.body ?? null, { headers, status });
|
|
958
962
|
}
|
|
959
963
|
return Response.json(declaration.body, { headers, status });
|
|
@@ -980,7 +984,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
980
984
|
},
|
|
981
985
|
get(target, property) {
|
|
982
986
|
if (_HttpInterceptorWorker.isHiddenRequestProperty(property)) {
|
|
983
|
-
return
|
|
987
|
+
return void 0;
|
|
984
988
|
}
|
|
985
989
|
return Reflect.get(target, property, target);
|
|
986
990
|
}
|
|
@@ -1034,7 +1038,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
1034
1038
|
},
|
|
1035
1039
|
get(target, property) {
|
|
1036
1040
|
if (_HttpInterceptorWorker.isHiddenResponseProperty(property)) {
|
|
1037
|
-
return
|
|
1041
|
+
return void 0;
|
|
1038
1042
|
}
|
|
1039
1043
|
return Reflect.get(target, property, target);
|
|
1040
1044
|
}
|
|
@@ -1281,10 +1285,10 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
1281
1285
|
return this._internalWorker;
|
|
1282
1286
|
}
|
|
1283
1287
|
createInternalWorker() {
|
|
1284
|
-
if (
|
|
1288
|
+
if (isServerSide() && "setupServer" in mswNode) {
|
|
1285
1289
|
return mswNode.setupServer(this.defaultHttpHandler);
|
|
1286
1290
|
}
|
|
1287
|
-
if (
|
|
1291
|
+
if (isClientSide() && "setupWorker" in mswBrowser) {
|
|
1288
1292
|
return mswBrowser.setupWorker(this.defaultHttpHandler);
|
|
1289
1293
|
}
|
|
1290
1294
|
throw new UnknownHttpInterceptorPlatformError_default();
|
|
@@ -1330,7 +1334,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
1330
1334
|
this.stopInNode(internalWorker);
|
|
1331
1335
|
}
|
|
1332
1336
|
this.clearHandlers();
|
|
1333
|
-
this._internalWorker =
|
|
1337
|
+
this._internalWorker = void 0;
|
|
1334
1338
|
super.setIsRunning(false);
|
|
1335
1339
|
});
|
|
1336
1340
|
}
|
|
@@ -1435,7 +1439,7 @@ var RemoteHttpRequestHandler = class {
|
|
|
1435
1439
|
}, "has"),
|
|
1436
1440
|
get: /* @__PURE__ */ __name((target, property) => {
|
|
1437
1441
|
if (this.isHiddenPropertyWhenSynced(property)) {
|
|
1438
|
-
return
|
|
1442
|
+
return void 0;
|
|
1439
1443
|
}
|
|
1440
1444
|
return Reflect.get(target, property);
|
|
1441
1445
|
}, "get")
|
|
@@ -1678,7 +1682,7 @@ var HttpInterceptorClient = class {
|
|
|
1678
1682
|
return handler;
|
|
1679
1683
|
}
|
|
1680
1684
|
}
|
|
1681
|
-
return
|
|
1685
|
+
return void 0;
|
|
1682
1686
|
}
|
|
1683
1687
|
checkTimes() {
|
|
1684
1688
|
for (const method of HTTP_METHODS) {
|
|
@@ -2172,7 +2176,7 @@ var WebSocketClient = class extends WebSocketHandler_default {
|
|
|
2172
2176
|
validateURLProtocol_default(this.url, SUPPORTED_WEB_SOCKET_PROTOCOLS);
|
|
2173
2177
|
}
|
|
2174
2178
|
isRunning() {
|
|
2175
|
-
return this.socket !==
|
|
2179
|
+
return this.socket !== void 0 && this.socket.readyState === this.socket.OPEN;
|
|
2176
2180
|
}
|
|
2177
2181
|
async start() {
|
|
2178
2182
|
this.socket = new ClientSocket(this.url);
|
|
@@ -2188,7 +2192,7 @@ var WebSocketClient = class extends WebSocketHandler_default {
|
|
|
2188
2192
|
const sockets = this.socket ? [this.socket] : [];
|
|
2189
2193
|
super.abortSocketMessages(sockets);
|
|
2190
2194
|
await super.closeClientSockets(sockets);
|
|
2191
|
-
this.socket =
|
|
2195
|
+
this.socket = void 0;
|
|
2192
2196
|
}
|
|
2193
2197
|
};
|
|
2194
2198
|
var WebSocketClient_default = WebSocketClient;
|
|
@@ -2252,10 +2256,10 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
2252
2256
|
return { wasLogged };
|
|
2253
2257
|
}, "handleUnhandledServerRequest");
|
|
2254
2258
|
readPlatform() {
|
|
2255
|
-
if (
|
|
2259
|
+
if (isServerSide()) {
|
|
2256
2260
|
return "node";
|
|
2257
2261
|
}
|
|
2258
|
-
if (
|
|
2262
|
+
if (isClientSide()) {
|
|
2259
2263
|
return "browser";
|
|
2260
2264
|
}
|
|
2261
2265
|
throw new UnknownHttpInterceptorPlatformError_default();
|
|
@@ -2303,7 +2307,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
2303
2307
|
}
|
|
2304
2308
|
this.httpHandlers.clear();
|
|
2305
2309
|
if (this._webSocketClient.isRunning()) {
|
|
2306
|
-
await this._webSocketClient.request("interceptors/workers/use/reset",
|
|
2310
|
+
await this._webSocketClient.request("interceptors/workers/use/reset", void 0);
|
|
2307
2311
|
}
|
|
2308
2312
|
}
|
|
2309
2313
|
async clearInterceptorHandlers(interceptor) {
|
|
@@ -2403,7 +2407,7 @@ var HttpInterceptorStore = class _HttpInterceptorStore {
|
|
|
2403
2407
|
return createdWorker;
|
|
2404
2408
|
}
|
|
2405
2409
|
clear() {
|
|
2406
|
-
this.class._localWorker =
|
|
2410
|
+
this.class._localWorker = void 0;
|
|
2407
2411
|
this.class.runningLocalInterceptors.clear();
|
|
2408
2412
|
this.class.remoteWorkers.clear();
|
|
2409
2413
|
this.class.runningRemoteInterceptors.clear();
|