@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.
- package/README.md +4 -5
- package/dist/{chunk-6TSSHQW5.mjs → chunk-NTRC2S4I.mjs} +253 -312
- package/dist/chunk-NTRC2S4I.mjs.map +1 -0
- package/dist/{chunk-R2ROSKU4.js → chunk-O6ZIPCUJ.js} +254 -313
- package/dist/chunk-O6ZIPCUJ.js.map +1 -0
- package/dist/cli.js +9 -9
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +5 -5
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +156 -176
- package/dist/http.js +265 -324
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +263 -323
- package/dist/http.mjs.map +1 -1
- package/dist/server.d.ts +20 -46
- package/dist/server.js +7 -7
- package/dist/server.mjs +1 -1
- package/package.json +4 -4
- package/src/cli/browser/init.ts +2 -2
- package/src/cli/server/start.ts +2 -2
- package/src/http/index.ts +6 -13
- package/src/http/interceptor/HttpInterceptorClient.ts +30 -15
- package/src/http/interceptor/LocalHttpInterceptor.ts +8 -8
- package/src/http/interceptor/RemoteHttpInterceptor.ts +8 -8
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +22 -0
- package/src/http/interceptor/factory.ts +1 -1
- package/src/http/interceptor/types/options.ts +4 -11
- package/src/http/interceptor/types/public.ts +44 -12
- package/src/http/interceptor/types/schema.ts +2 -2
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +6 -31
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +15 -5
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +2 -2
- package/src/http/requestHandler/errors/TimesCheckError.ts +15 -14
- package/src/http/requestHandler/types/public.ts +16 -8
- package/src/server/index.ts +1 -11
- package/src/utils/console.ts +2 -2
- package/dist/chunk-6TSSHQW5.mjs.map +0 -1
- package/dist/chunk-R2ROSKU4.js.map +0 -1
- package/src/http/interceptorWorker/HttpInterceptorWorkerStore.ts +0 -34
- package/src/http/namespace/HttpInterceptorNamespace.ts +0 -81
- package/src/server/namespace/InterceptorServerNamespace.ts +0 -21
package/dist/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var color2 = require('picocolors');
|
|
3
4
|
var http = require('@zimic/http');
|
|
4
|
-
var chalk2 = require('chalk');
|
|
5
5
|
var msw = require('msw');
|
|
6
6
|
var mswBrowser = require('msw/browser');
|
|
7
7
|
var mswNode = require('msw/node');
|
|
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
return Object.freeze(n);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var color2__default = /*#__PURE__*/_interopDefault(color2);
|
|
31
31
|
var mswBrowser__namespace = /*#__PURE__*/_interopNamespace(mswBrowser);
|
|
32
32
|
var mswNode__namespace = /*#__PURE__*/_interopNamespace(mswNode);
|
|
33
33
|
var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
|
|
@@ -35,6 +35,44 @@ var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
|
|
|
35
35
|
var __defProp = Object.defineProperty;
|
|
36
36
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
37
37
|
|
|
38
|
+
// src/http/interceptor/errors/RunningHttpInterceptorError.ts
|
|
39
|
+
var RunningHttpInterceptorError = class extends Error {
|
|
40
|
+
static {
|
|
41
|
+
__name(this, "RunningHttpInterceptorError");
|
|
42
|
+
}
|
|
43
|
+
constructor(additionalMessage) {
|
|
44
|
+
super(`The interceptor is running.${additionalMessage}`);
|
|
45
|
+
this.name = "RunningHttpInterceptorError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var RunningHttpInterceptorError_default = RunningHttpInterceptorError;
|
|
49
|
+
|
|
50
|
+
// src/http/interceptor/errors/NotRunningHttpInterceptorError.ts
|
|
51
|
+
var NotRunningHttpInterceptorError = class extends Error {
|
|
52
|
+
static {
|
|
53
|
+
__name(this, "NotRunningHttpInterceptorError");
|
|
54
|
+
}
|
|
55
|
+
constructor() {
|
|
56
|
+
super("Interceptor is not running. Did you forget to call `await interceptor.start()`?");
|
|
57
|
+
this.name = "NotRunningHttpInterceptorError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var NotRunningHttpInterceptorError_default = NotRunningHttpInterceptorError;
|
|
61
|
+
|
|
62
|
+
// src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts
|
|
63
|
+
var UnknownHttpInterceptorPlatformError = class extends Error {
|
|
64
|
+
static {
|
|
65
|
+
__name(this, "UnknownHttpInterceptorPlatformError");
|
|
66
|
+
}
|
|
67
|
+
/* istanbul ignore next -- @preserve
|
|
68
|
+
* Ignoring because checking unknown platforms is currently not possible in our Vitest setup. */
|
|
69
|
+
constructor() {
|
|
70
|
+
super("Unknown interceptor platform.");
|
|
71
|
+
this.name = "UnknownHttpInterceptorPlatform";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var UnknownHttpInterceptorPlatformError_default = UnknownHttpInterceptorPlatformError;
|
|
75
|
+
|
|
38
76
|
// src/http/interceptor/errors/UnknownHttpInterceptorTypeError.ts
|
|
39
77
|
var UnknownHttpInterceptorTypeError = class extends TypeError {
|
|
40
78
|
static {
|
|
@@ -49,102 +87,73 @@ var UnknownHttpInterceptorTypeError = class extends TypeError {
|
|
|
49
87
|
};
|
|
50
88
|
var UnknownHttpInterceptorTypeError_default = UnknownHttpInterceptorTypeError;
|
|
51
89
|
|
|
52
|
-
//
|
|
53
|
-
var
|
|
54
|
-
|
|
90
|
+
// src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts
|
|
91
|
+
var RequestSavingSafeLimitExceededError = class extends TypeError {
|
|
92
|
+
static {
|
|
93
|
+
__name(this, "RequestSavingSafeLimitExceededError");
|
|
94
|
+
}
|
|
95
|
+
constructor(numberOfSavedRequests, safeLimit) {
|
|
96
|
+
super(
|
|
97
|
+
`The number of intercepted requests saved in memory (${numberOfSavedRequests}) exceeded the safe limit of ${safeLimit}. Did you forget to call \`interceptor.clear()\`?
|
|
55
98
|
|
|
56
|
-
|
|
57
|
-
async function blobContains(blob, otherBlob) {
|
|
58
|
-
return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
|
|
59
|
-
}
|
|
60
|
-
__name(blobContains, "blobContains");
|
|
61
|
-
__name2(blobContains, "blobContains");
|
|
62
|
-
var blobContains_default = blobContains;
|
|
99
|
+
If you need to save requests, make sure to regularly call \`interceptor.clear()\`. Alternatively, you can hide this warning by increasing \`requestSaving.safeLimit\` in your interceptor. Note that saving too many requests in memory can lead to performance issues.
|
|
63
100
|
|
|
64
|
-
|
|
65
|
-
async function blobEquals(blob, otherBlob) {
|
|
66
|
-
return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
|
|
67
|
-
}
|
|
68
|
-
__name(blobEquals, "blobEquals");
|
|
69
|
-
__name2(blobEquals, "blobEquals");
|
|
70
|
-
var blobEquals_default = blobEquals;
|
|
101
|
+
If you do not need to save requests, consider setting \`requestSaving.enabled: false\` in your interceptor.
|
|
71
102
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
__name(isPrimitiveJSONValue, "isPrimitiveJSONValue");
|
|
77
|
-
function jsonEquals(value, otherValue) {
|
|
78
|
-
if (isPrimitiveJSONValue(value)) {
|
|
79
|
-
return value === otherValue;
|
|
80
|
-
}
|
|
81
|
-
if (isPrimitiveJSONValue(otherValue)) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (Array.isArray(value)) {
|
|
85
|
-
if (!Array.isArray(otherValue)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (value.length !== otherValue.length) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
return value.every((item, index) => jsonEquals(item, otherValue[index]));
|
|
103
|
+
Learn more: https://github.com/zimicjs/zimic/wiki/api\u2010zimic\u2010interceptor\u2010http#saving-requests`
|
|
104
|
+
);
|
|
105
|
+
this.name = "RequestSavingSafeLimitExceededError";
|
|
92
106
|
}
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
};
|
|
108
|
+
var RequestSavingSafeLimitExceededError_default = RequestSavingSafeLimitExceededError;
|
|
109
|
+
|
|
110
|
+
// src/http/interceptorWorker/errors/InvalidFormDataError.ts
|
|
111
|
+
var InvalidFormDataError = class extends SyntaxError {
|
|
112
|
+
static {
|
|
113
|
+
__name(this, "InvalidFormDataError");
|
|
95
114
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return false;
|
|
115
|
+
constructor(value) {
|
|
116
|
+
super(`Failed to parse value as form data: ${value}`);
|
|
117
|
+
this.name = "InvalidFormDataError";
|
|
100
118
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
__name(
|
|
108
|
-
function jsonContains(value, otherValue) {
|
|
109
|
-
if (isPrimitiveJSONValue(value)) {
|
|
110
|
-
return value === otherValue;
|
|
119
|
+
};
|
|
120
|
+
var InvalidFormDataError_default = InvalidFormDataError;
|
|
121
|
+
|
|
122
|
+
// src/http/interceptorWorker/errors/InvalidJSONError.ts
|
|
123
|
+
var InvalidJSONError = class extends SyntaxError {
|
|
124
|
+
static {
|
|
125
|
+
__name(this, "InvalidJSONError");
|
|
111
126
|
}
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
constructor(value) {
|
|
128
|
+
super(`Failed to parse value as JSON: ${value}`);
|
|
129
|
+
this.name = "InvalidJSONError";
|
|
114
130
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (jsonContains(value[index], otherItem)) {
|
|
126
|
-
lastMatchedIndex = index;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
|
-
});
|
|
131
|
+
};
|
|
132
|
+
var InvalidJSONError_default = InvalidJSONError;
|
|
133
|
+
|
|
134
|
+
// src/cli/browser/shared/constants.ts
|
|
135
|
+
var SERVICE_WORKER_FILE_NAME = "mockServiceWorker.js";
|
|
136
|
+
|
|
137
|
+
// src/http/interceptorWorker/errors/UnregisteredBrowserServiceWorkerError.ts
|
|
138
|
+
var UnregisteredBrowserServiceWorkerError = class extends Error {
|
|
139
|
+
static {
|
|
140
|
+
__name(this, "UnregisteredBrowserServiceWorkerError");
|
|
132
141
|
}
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
constructor() {
|
|
143
|
+
super(
|
|
144
|
+
`Failed to register the browser service worker: script '${window.location.origin}/${SERVICE_WORKER_FILE_NAME}' not found.
|
|
145
|
+
|
|
146
|
+
Did you forget to run \`zimic-interceptor browser init <publicDirectory>\`?
|
|
147
|
+
|
|
148
|
+
Learn more: https://github.com/zimicjs/zimic/wiki/getting\u2010started#client-side-post-install`
|
|
149
|
+
);
|
|
150
|
+
this.name = "UnregisteredBrowserServiceWorkerError";
|
|
135
151
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (valueKeys.length < otherValueKeys.length) {
|
|
139
|
-
return false;
|
|
152
|
+
static matchesRawError(error) {
|
|
153
|
+
return error instanceof Error && error.message.toLowerCase().includes("service worker script does not exist at the given path");
|
|
140
154
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const subOtherValue = otherValue[key];
|
|
144
|
-
return jsonContains(subValue, subOtherValue);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
__name(jsonContains, "jsonContains");
|
|
155
|
+
};
|
|
156
|
+
var UnregisteredBrowserServiceWorkerError_default = UnregisteredBrowserServiceWorkerError;
|
|
148
157
|
|
|
149
158
|
// src/http/requestHandler/errors/DisabledRequestSavingError.ts
|
|
150
159
|
var DisabledRequestSavingError = class extends TypeError {
|
|
@@ -153,24 +162,16 @@ var DisabledRequestSavingError = class extends TypeError {
|
|
|
153
162
|
}
|
|
154
163
|
constructor() {
|
|
155
164
|
super(
|
|
156
|
-
"Intercepted requests are not saved
|
|
165
|
+
"Intercepted requests are not being saved. Did you forget to use `requestSaving.enabled: true` in your interceptor?\n\nLearn more: https://github.com/zimicjs/zimic/wiki/api\u2010zimic\u2010interceptor\u2010http#saving-requests"
|
|
157
166
|
);
|
|
158
167
|
this.name = "DisabledRequestSavingError";
|
|
159
168
|
}
|
|
160
169
|
};
|
|
161
170
|
var DisabledRequestSavingError_default = DisabledRequestSavingError;
|
|
162
171
|
|
|
163
|
-
//
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
__name(this, "NoResponseDefinitionError");
|
|
167
|
-
}
|
|
168
|
-
constructor() {
|
|
169
|
-
super("Cannot generate a response without a definition. Use .respond() to set a response.");
|
|
170
|
-
this.name = "NoResponseDefinitionError";
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
var NoResponseDefinitionError_default = NoResponseDefinitionError;
|
|
172
|
+
// ../zimic-utils/dist/chunk-PAWJFY3S.mjs
|
|
173
|
+
var __defProp2 = Object.defineProperty;
|
|
174
|
+
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
|
174
175
|
|
|
175
176
|
// ../zimic-utils/dist/chunk-3O5CS47X.mjs
|
|
176
177
|
function isDefined(value) {
|
|
@@ -274,7 +275,7 @@ __name(formatValueToLog, "formatValueToLog");
|
|
|
274
275
|
function logWithPrefix(messageOrMessages, options = {}) {
|
|
275
276
|
const { method = "log" } = options;
|
|
276
277
|
const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
|
|
277
|
-
console[method](
|
|
278
|
+
console[method](color2__default.default.cyan("[@zimic/interceptor]"), ...messages);
|
|
278
279
|
}
|
|
279
280
|
__name(logWithPrefix, "logWithPrefix");
|
|
280
281
|
|
|
@@ -300,14 +301,14 @@ function createMessageHeader({
|
|
|
300
301
|
|
|
301
302
|
Requests evaluated by this handler:
|
|
302
303
|
|
|
303
|
-
${
|
|
304
|
-
${
|
|
304
|
+
${color2__default.default.green("- Expected")}
|
|
305
|
+
${color2__default.default.red("+ Received")}`
|
|
305
306
|
].filter((part) => part !== false).join("");
|
|
306
307
|
}
|
|
307
308
|
__name(createMessageHeader, "createMessageHeader");
|
|
308
|
-
function createMessageDiffs({
|
|
309
|
-
if (!
|
|
310
|
-
return "Tip:
|
|
309
|
+
function createMessageDiffs({ requestSaving, unmatchedRequestGroups }) {
|
|
310
|
+
if (!requestSaving.enabled) {
|
|
311
|
+
return "Tip: use `requestSaving.enabled: true` in your interceptor for more details about the unmatched requests.";
|
|
311
312
|
}
|
|
312
313
|
return unmatchedRequestGroups.map(({ request, diff }, index) => {
|
|
313
314
|
const requestNumber = index + 1;
|
|
@@ -316,22 +317,22 @@ function createMessageDiffs({ hasSavedRequests, unmatchedRequestGroups }) {
|
|
|
316
317
|
messageParts.push("Computed restriction:");
|
|
317
318
|
const stringifiedExpected = stringifyValueToLog(diff.computed.expected);
|
|
318
319
|
const stringifiedReceived = stringifyValueToLog(diff.computed.received);
|
|
319
|
-
messageParts.push(` ${
|
|
320
|
-
messageParts.push(` ${
|
|
320
|
+
messageParts.push(` ${color2__default.default.green(`- return ${stringifiedExpected}`)}`);
|
|
321
|
+
messageParts.push(` ${color2__default.default.red(`+ return ${stringifiedReceived}`)}`);
|
|
321
322
|
}
|
|
322
323
|
if (diff.headers) {
|
|
323
324
|
messageParts.push("Headers:");
|
|
324
325
|
const stringifiedExpected = stringifyValueToLog(diff.headers.expected);
|
|
325
326
|
const stringifiedReceived = stringifyValueToLog(diff.headers.received);
|
|
326
|
-
messageParts.push(` ${
|
|
327
|
-
messageParts.push(` ${
|
|
327
|
+
messageParts.push(` ${color2__default.default.green(`- ${stringifiedExpected}`)}`);
|
|
328
|
+
messageParts.push(` ${color2__default.default.red(`+ ${stringifiedReceived}`)}`);
|
|
328
329
|
}
|
|
329
330
|
if (diff.searchParams) {
|
|
330
331
|
messageParts.push("Search params:");
|
|
331
332
|
const stringifiedExpected = stringifyValueToLog(diff.searchParams.expected);
|
|
332
333
|
const stringifiedReceived = stringifyValueToLog(diff.searchParams.received);
|
|
333
|
-
messageParts.push(` ${
|
|
334
|
-
messageParts.push(` ${
|
|
334
|
+
messageParts.push(` ${color2__default.default.green(`- ${stringifiedExpected}`)}`);
|
|
335
|
+
messageParts.push(` ${color2__default.default.red(`+ ${stringifiedReceived}`)}`);
|
|
335
336
|
}
|
|
336
337
|
if (diff.body) {
|
|
337
338
|
messageParts.push("Body:");
|
|
@@ -341,8 +342,8 @@ function createMessageDiffs({ hasSavedRequests, unmatchedRequestGroups }) {
|
|
|
341
342
|
const stringifiedReceived = stringifyValueToLog(diff.body.received, {
|
|
342
343
|
includeClassName: { searchParams: true }
|
|
343
344
|
});
|
|
344
|
-
messageParts.push(` ${
|
|
345
|
-
messageParts.push(` ${
|
|
345
|
+
messageParts.push(` ${color2__default.default.green(`- ${stringifiedExpected}`)}`);
|
|
346
|
+
messageParts.push(` ${color2__default.default.red(`+ ${stringifiedReceived}`)}`);
|
|
346
347
|
}
|
|
347
348
|
return messageParts.join("\n ");
|
|
348
349
|
}).join("\n\n");
|
|
@@ -372,6 +373,111 @@ var TimesCheckError = class extends TypeError {
|
|
|
372
373
|
};
|
|
373
374
|
var TimesCheckError_default = TimesCheckError;
|
|
374
375
|
|
|
376
|
+
// ../zimic-utils/dist/data/blobContains.mjs
|
|
377
|
+
async function blobContains(blob, otherBlob) {
|
|
378
|
+
return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
|
|
379
|
+
}
|
|
380
|
+
__name(blobContains, "blobContains");
|
|
381
|
+
__name2(blobContains, "blobContains");
|
|
382
|
+
var blobContains_default = blobContains;
|
|
383
|
+
|
|
384
|
+
// ../zimic-utils/dist/chunk-HVLEF6VF.mjs
|
|
385
|
+
async function blobEquals(blob, otherBlob) {
|
|
386
|
+
return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
|
|
387
|
+
}
|
|
388
|
+
__name(blobEquals, "blobEquals");
|
|
389
|
+
__name2(blobEquals, "blobEquals");
|
|
390
|
+
var blobEquals_default = blobEquals;
|
|
391
|
+
|
|
392
|
+
// src/utils/json.ts
|
|
393
|
+
function isPrimitiveJSONValue(value) {
|
|
394
|
+
return typeof value !== "object" || value === null;
|
|
395
|
+
}
|
|
396
|
+
__name(isPrimitiveJSONValue, "isPrimitiveJSONValue");
|
|
397
|
+
function jsonEquals(value, otherValue) {
|
|
398
|
+
if (isPrimitiveJSONValue(value)) {
|
|
399
|
+
return value === otherValue;
|
|
400
|
+
}
|
|
401
|
+
if (isPrimitiveJSONValue(otherValue)) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
if (Array.isArray(value)) {
|
|
405
|
+
if (!Array.isArray(otherValue)) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
if (value.length !== otherValue.length) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
return value.every((item, index) => jsonEquals(item, otherValue[index]));
|
|
412
|
+
}
|
|
413
|
+
if (Array.isArray(otherValue)) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
const valueKeys = Object.keys(value);
|
|
417
|
+
const otherValueKeys = Object.keys(otherValue);
|
|
418
|
+
if (valueKeys.length !== otherValueKeys.length) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
return valueKeys.every((key) => {
|
|
422
|
+
const subValue = value[key];
|
|
423
|
+
const subOtherValue = otherValue[key];
|
|
424
|
+
return jsonEquals(subValue, subOtherValue);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
__name(jsonEquals, "jsonEquals");
|
|
428
|
+
function jsonContains(value, otherValue) {
|
|
429
|
+
if (isPrimitiveJSONValue(value)) {
|
|
430
|
+
return value === otherValue;
|
|
431
|
+
}
|
|
432
|
+
if (isPrimitiveJSONValue(otherValue)) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
if (Array.isArray(value)) {
|
|
436
|
+
if (!Array.isArray(otherValue)) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
if (value.length < otherValue.length) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
let lastMatchedIndex = -1;
|
|
443
|
+
return otherValue.every((otherItem) => {
|
|
444
|
+
for (let index = lastMatchedIndex + 1; index < value.length; index++) {
|
|
445
|
+
if (jsonContains(value[index], otherItem)) {
|
|
446
|
+
lastMatchedIndex = index;
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (Array.isArray(otherValue)) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
const valueKeys = Object.keys(value);
|
|
457
|
+
const otherValueKeys = Object.keys(otherValue);
|
|
458
|
+
if (valueKeys.length < otherValueKeys.length) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
return otherValueKeys.every((key) => {
|
|
462
|
+
const subValue = value[key];
|
|
463
|
+
const subOtherValue = otherValue[key];
|
|
464
|
+
return jsonContains(subValue, subOtherValue);
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
__name(jsonContains, "jsonContains");
|
|
468
|
+
|
|
469
|
+
// src/http/requestHandler/errors/NoResponseDefinitionError.ts
|
|
470
|
+
var NoResponseDefinitionError = class extends TypeError {
|
|
471
|
+
static {
|
|
472
|
+
__name(this, "NoResponseDefinitionError");
|
|
473
|
+
}
|
|
474
|
+
constructor() {
|
|
475
|
+
super("Cannot generate a response without a definition. Use .respond() to set a response.");
|
|
476
|
+
this.name = "NoResponseDefinitionError";
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var NoResponseDefinitionError_default = NoResponseDefinitionError;
|
|
480
|
+
|
|
375
481
|
// src/http/requestHandler/errors/TimesDeclarationPointer.ts
|
|
376
482
|
var TimesDeclarationPointer = class extends Error {
|
|
377
483
|
static {
|
|
@@ -417,7 +523,7 @@ var HttpRequestHandlerClient = class {
|
|
|
417
523
|
newThis.createResponseDeclaration = this.isResponseDeclarationFactory(declaration) ? declaration : () => declaration;
|
|
418
524
|
newThis.numberOfMatchedRequests = 0;
|
|
419
525
|
newThis.unmatchedRequestGroups.length = 0;
|
|
420
|
-
newThis.
|
|
526
|
+
newThis.clearInterceptedRequests();
|
|
421
527
|
this.interceptor.registerRequestHandler(this.handler);
|
|
422
528
|
return newThis;
|
|
423
529
|
}
|
|
@@ -441,7 +547,7 @@ var HttpRequestHandlerClient = class {
|
|
|
441
547
|
declarationPointer: this.timesDeclarationPointer,
|
|
442
548
|
unmatchedRequestGroups: this.unmatchedRequestGroups,
|
|
443
549
|
hasRestrictions: this.restrictions.length > 0,
|
|
444
|
-
|
|
550
|
+
requestSaving: this.interceptor.requestSaving
|
|
445
551
|
});
|
|
446
552
|
}
|
|
447
553
|
}
|
|
@@ -453,7 +559,7 @@ var HttpRequestHandlerClient = class {
|
|
|
453
559
|
this.timesDeclarationPointer = void 0;
|
|
454
560
|
this.numberOfMatchedRequests = 0;
|
|
455
561
|
this.unmatchedRequestGroups.length = 0;
|
|
456
|
-
this.
|
|
562
|
+
this.clearInterceptedRequests();
|
|
457
563
|
this.createResponseDeclaration = void 0;
|
|
458
564
|
return this;
|
|
459
565
|
}
|
|
@@ -466,7 +572,7 @@ var HttpRequestHandlerClient = class {
|
|
|
466
572
|
if (restrictionsMatch.value) {
|
|
467
573
|
this.numberOfMatchedRequests++;
|
|
468
574
|
} else {
|
|
469
|
-
const shouldSaveUnmatchedGroup = this.interceptor.
|
|
575
|
+
const shouldSaveUnmatchedGroup = this.interceptor.requestSaving.enabled && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
|
|
470
576
|
if (shouldSaveUnmatchedGroup) {
|
|
471
577
|
this.unmatchedRequestGroups.push({ request, diff: restrictionsMatch.diff });
|
|
472
578
|
}
|
|
@@ -600,6 +706,11 @@ var HttpRequestHandlerClient = class {
|
|
|
600
706
|
saveInterceptedRequest(request, response) {
|
|
601
707
|
const interceptedRequest = this.createInterceptedRequest(request, response);
|
|
602
708
|
this._requests.push(interceptedRequest);
|
|
709
|
+
this.interceptor.incrementNumberOfSavedRequests(1);
|
|
710
|
+
}
|
|
711
|
+
clearInterceptedRequests() {
|
|
712
|
+
this.interceptor.incrementNumberOfSavedRequests(-this._requests.length);
|
|
713
|
+
this._requests.length = 0;
|
|
603
714
|
}
|
|
604
715
|
createInterceptedRequest(request, response) {
|
|
605
716
|
const interceptedRequest = request;
|
|
@@ -612,7 +723,7 @@ var HttpRequestHandlerClient = class {
|
|
|
612
723
|
return interceptedRequest;
|
|
613
724
|
}
|
|
614
725
|
get requests() {
|
|
615
|
-
if (!this.interceptor.
|
|
726
|
+
if (!this.interceptor.requestSaving.enabled) {
|
|
616
727
|
throw new DisabledRequestSavingError_default();
|
|
617
728
|
}
|
|
618
729
|
return this._requests;
|
|
@@ -787,53 +898,6 @@ var DEFAULT_UNHANDLED_REQUEST_STRATEGY = Object.freeze({
|
|
|
787
898
|
})
|
|
788
899
|
});
|
|
789
900
|
|
|
790
|
-
// src/http/interceptorWorker/errors/InvalidFormDataError.ts
|
|
791
|
-
var InvalidFormDataError = class extends SyntaxError {
|
|
792
|
-
static {
|
|
793
|
-
__name(this, "InvalidFormDataError");
|
|
794
|
-
}
|
|
795
|
-
constructor(value) {
|
|
796
|
-
super(`Failed to parse value as form data: ${value}`);
|
|
797
|
-
this.name = "InvalidFormDataError";
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
var InvalidFormDataError_default = InvalidFormDataError;
|
|
801
|
-
|
|
802
|
-
// src/http/interceptorWorker/errors/InvalidJSONError.ts
|
|
803
|
-
var InvalidJSONError = class extends SyntaxError {
|
|
804
|
-
static {
|
|
805
|
-
__name(this, "InvalidJSONError");
|
|
806
|
-
}
|
|
807
|
-
constructor(value) {
|
|
808
|
-
super(`Failed to parse value as JSON: ${value}`);
|
|
809
|
-
this.name = "InvalidJSONError";
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
var InvalidJSONError_default = InvalidJSONError;
|
|
813
|
-
|
|
814
|
-
// src/http/interceptorWorker/HttpInterceptorWorkerStore.ts
|
|
815
|
-
var HttpInterceptorWorkerStore = class _HttpInterceptorWorkerStore {
|
|
816
|
-
static {
|
|
817
|
-
__name(this, "HttpInterceptorWorkerStore");
|
|
818
|
-
}
|
|
819
|
-
static _defaultOnUnhandledRequest = {
|
|
820
|
-
local: { ...DEFAULT_UNHANDLED_REQUEST_STRATEGY.local },
|
|
821
|
-
remote: { ...DEFAULT_UNHANDLED_REQUEST_STRATEGY.remote }
|
|
822
|
-
};
|
|
823
|
-
class = _HttpInterceptorWorkerStore;
|
|
824
|
-
defaultOnUnhandledRequest(interceptorType) {
|
|
825
|
-
return this.class._defaultOnUnhandledRequest[interceptorType];
|
|
826
|
-
}
|
|
827
|
-
setDefaultOnUnhandledRequest(interceptorType, strategy) {
|
|
828
|
-
if (interceptorType === "local") {
|
|
829
|
-
this.class._defaultOnUnhandledRequest[interceptorType] = strategy;
|
|
830
|
-
} else {
|
|
831
|
-
this.class._defaultOnUnhandledRequest[interceptorType] = strategy;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
var HttpInterceptorWorkerStore_default = HttpInterceptorWorkerStore;
|
|
836
|
-
|
|
837
901
|
// src/http/interceptorWorker/HttpInterceptorWorker.ts
|
|
838
902
|
var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
839
903
|
static {
|
|
@@ -843,7 +907,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
843
907
|
isRunning = false;
|
|
844
908
|
startingPromise;
|
|
845
909
|
stoppingPromise;
|
|
846
|
-
store = new HttpInterceptorWorkerStore_default();
|
|
847
910
|
runningInterceptors = [];
|
|
848
911
|
async sharedStart(internalStart) {
|
|
849
912
|
if (this.isRunning) {
|
|
@@ -902,24 +965,18 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
902
965
|
);
|
|
903
966
|
}
|
|
904
967
|
async getUnhandledRequestStrategyCandidates(request, interceptorType) {
|
|
905
|
-
const globalDefaultStrategy =
|
|
968
|
+
const globalDefaultStrategy = DEFAULT_UNHANDLED_REQUEST_STRATEGY[interceptorType];
|
|
906
969
|
try {
|
|
907
970
|
const interceptor = this.findInterceptorByRequestBaseURL(request);
|
|
908
971
|
if (!interceptor) {
|
|
909
972
|
return [];
|
|
910
973
|
}
|
|
911
974
|
const requestClone = request.clone();
|
|
912
|
-
const
|
|
913
|
-
|
|
914
|
-
this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor)
|
|
915
|
-
]);
|
|
916
|
-
const candidatesOrPromises = [interceptorStrategy, defaultStrategy, globalDefaultStrategy];
|
|
917
|
-
const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined_default));
|
|
918
|
-
return candidateStrategies;
|
|
975
|
+
const interceptorStrategy = await this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor);
|
|
976
|
+
return [interceptorStrategy, globalDefaultStrategy].filter(isDefined_default);
|
|
919
977
|
} catch (error) {
|
|
920
978
|
console.error(error);
|
|
921
|
-
|
|
922
|
-
return candidateStrategies;
|
|
979
|
+
return [globalDefaultStrategy];
|
|
923
980
|
}
|
|
924
981
|
}
|
|
925
982
|
registerRunningInterceptor(interceptor) {
|
|
@@ -934,17 +991,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
934
991
|
});
|
|
935
992
|
return interceptor;
|
|
936
993
|
}
|
|
937
|
-
getGlobalDefaultUnhandledRequestStrategy(interceptorType) {
|
|
938
|
-
return DEFAULT_UNHANDLED_REQUEST_STRATEGY[interceptorType];
|
|
939
|
-
}
|
|
940
|
-
async getDefaultUnhandledRequestStrategy(request, interceptorType) {
|
|
941
|
-
const defaultStrategyOrFactory = this.store.defaultOnUnhandledRequest(interceptorType);
|
|
942
|
-
if (typeof defaultStrategyOrFactory === "function") {
|
|
943
|
-
const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
|
|
944
|
-
return defaultStrategyOrFactory(parsedRequest);
|
|
945
|
-
}
|
|
946
|
-
return defaultStrategyOrFactory;
|
|
947
|
-
}
|
|
948
994
|
async getInterceptorUnhandledRequestStrategy(request, interceptor) {
|
|
949
995
|
if (typeof interceptor.onUnhandledRequest === "function") {
|
|
950
996
|
const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
|
|
@@ -1158,7 +1204,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
1158
1204
|
]);
|
|
1159
1205
|
logWithPrefix(
|
|
1160
1206
|
[
|
|
1161
|
-
`${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ?
|
|
1207
|
+
`${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ? color2__default.default.yellow("bypassed") : color2__default.default.red("rejected")}.
|
|
1162
1208
|
|
|
1163
1209
|
`,
|
|
1164
1210
|
`${request.method} ${request.url}`,
|
|
@@ -1206,58 +1252,6 @@ function validateURLPathParams(url) {
|
|
|
1206
1252
|
__name(validateURLPathParams, "validateURLPathParams");
|
|
1207
1253
|
__name2(validateURLPathParams, "validateURLPathParams");
|
|
1208
1254
|
var validateURLPathParams_default = validateURLPathParams;
|
|
1209
|
-
|
|
1210
|
-
// src/http/interceptor/errors/NotRunningHttpInterceptorError.ts
|
|
1211
|
-
var NotRunningHttpInterceptorError = class extends Error {
|
|
1212
|
-
static {
|
|
1213
|
-
__name(this, "NotRunningHttpInterceptorError");
|
|
1214
|
-
}
|
|
1215
|
-
constructor() {
|
|
1216
|
-
super("Interceptor is not running. Did you forget to call `await interceptor.start()`?");
|
|
1217
|
-
this.name = "NotRunningHttpInterceptorError";
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
var NotRunningHttpInterceptorError_default = NotRunningHttpInterceptorError;
|
|
1221
|
-
|
|
1222
|
-
// src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts
|
|
1223
|
-
var UnknownHttpInterceptorPlatformError = class extends Error {
|
|
1224
|
-
static {
|
|
1225
|
-
__name(this, "UnknownHttpInterceptorPlatformError");
|
|
1226
|
-
}
|
|
1227
|
-
/* istanbul ignore next -- @preserve
|
|
1228
|
-
* Ignoring because checking unknown platforms is currently not possible in our Vitest setup. */
|
|
1229
|
-
constructor() {
|
|
1230
|
-
super("Unknown interceptor platform.");
|
|
1231
|
-
this.name = "UnknownHttpInterceptorPlatform";
|
|
1232
|
-
}
|
|
1233
|
-
};
|
|
1234
|
-
var UnknownHttpInterceptorPlatformError_default = UnknownHttpInterceptorPlatformError;
|
|
1235
|
-
|
|
1236
|
-
// src/cli/browser/shared/constants.ts
|
|
1237
|
-
var SERVICE_WORKER_FILE_NAME = "mockServiceWorker.js";
|
|
1238
|
-
|
|
1239
|
-
// src/http/interceptorWorker/errors/UnregisteredBrowserServiceWorkerError.ts
|
|
1240
|
-
var UnregisteredBrowserServiceWorkerError = class extends Error {
|
|
1241
|
-
static {
|
|
1242
|
-
__name(this, "UnregisteredBrowserServiceWorkerError");
|
|
1243
|
-
}
|
|
1244
|
-
constructor() {
|
|
1245
|
-
super(
|
|
1246
|
-
`Failed to register the browser service worker: script '${window.location.origin}/${SERVICE_WORKER_FILE_NAME}' not found.
|
|
1247
|
-
|
|
1248
|
-
Did you forget to run \`zimic-interceptor browser init <publicDirectory>\`?
|
|
1249
|
-
|
|
1250
|
-
Learn more: https://github.com/zimicjs/zimic/wiki/getting\u2010started#client-side-post-install`
|
|
1251
|
-
);
|
|
1252
|
-
this.name = "UnregisteredBrowserServiceWorkerError";
|
|
1253
|
-
}
|
|
1254
|
-
static matchesRawError(error) {
|
|
1255
|
-
return error instanceof Error && error.message.toLowerCase().includes("service worker script does not exist at the given path");
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
var UnregisteredBrowserServiceWorkerError_default = UnregisteredBrowserServiceWorkerError;
|
|
1259
|
-
|
|
1260
|
-
// src/http/interceptorWorker/LocalHttpInterceptorWorker.ts
|
|
1261
1255
|
var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
1262
1256
|
static {
|
|
1263
1257
|
__name(this, "LocalHttpInterceptorWorker");
|
|
@@ -1515,20 +1509,9 @@ var RemoteHttpRequestHandler = class {
|
|
|
1515
1509
|
};
|
|
1516
1510
|
var RemoteHttpRequestHandler_default = RemoteHttpRequestHandler;
|
|
1517
1511
|
|
|
1518
|
-
// src/http/interceptor/errors/RunningHttpInterceptorError.ts
|
|
1519
|
-
var RunningHttpInterceptorError = class extends Error {
|
|
1520
|
-
static {
|
|
1521
|
-
__name(this, "RunningHttpInterceptorError");
|
|
1522
|
-
}
|
|
1523
|
-
constructor(additionalMessage) {
|
|
1524
|
-
super(`The interceptor is running.${additionalMessage}`);
|
|
1525
|
-
this.name = "RunningHttpInterceptorError";
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
var RunningHttpInterceptorError_default = RunningHttpInterceptorError;
|
|
1529
|
-
|
|
1530
1512
|
// src/http/interceptor/HttpInterceptorClient.ts
|
|
1531
1513
|
var SUPPORTED_BASE_URL_PROTOCOLS = Object.freeze(["http", "https"]);
|
|
1514
|
+
var DEFAULT_REQUEST_SAVING_SAFE_LIMIT = 1e3;
|
|
1532
1515
|
var HttpInterceptorClient = class {
|
|
1533
1516
|
static {
|
|
1534
1517
|
__name(this, "HttpInterceptorClient");
|
|
@@ -1536,7 +1519,8 @@ var HttpInterceptorClient = class {
|
|
|
1536
1519
|
worker;
|
|
1537
1520
|
store;
|
|
1538
1521
|
_baseURL;
|
|
1539
|
-
|
|
1522
|
+
requestSaving;
|
|
1523
|
+
numberOfSavedRequests = 0;
|
|
1540
1524
|
onUnhandledRequest;
|
|
1541
1525
|
isRunning = false;
|
|
1542
1526
|
Handler;
|
|
@@ -1553,10 +1537,16 @@ var HttpInterceptorClient = class {
|
|
|
1553
1537
|
this.worker = options.worker;
|
|
1554
1538
|
this.store = options.store;
|
|
1555
1539
|
this.baseURL = options.baseURL;
|
|
1556
|
-
this.
|
|
1540
|
+
this.requestSaving = {
|
|
1541
|
+
enabled: options.requestSaving?.enabled ?? this.getDefaultRequestSavingEnabled(),
|
|
1542
|
+
safeLimit: options.requestSaving?.safeLimit ?? DEFAULT_REQUEST_SAVING_SAFE_LIMIT
|
|
1543
|
+
};
|
|
1557
1544
|
this.onUnhandledRequest = options.onUnhandledRequest;
|
|
1558
1545
|
this.Handler = options.Handler;
|
|
1559
1546
|
}
|
|
1547
|
+
getDefaultRequestSavingEnabled() {
|
|
1548
|
+
return isServerSide() ? process.env.NODE_ENV === "test" : false;
|
|
1549
|
+
}
|
|
1560
1550
|
get baseURL() {
|
|
1561
1551
|
return this._baseURL;
|
|
1562
1552
|
}
|
|
@@ -1576,15 +1566,6 @@ var HttpInterceptorClient = class {
|
|
|
1576
1566
|
}
|
|
1577
1567
|
return this.baseURL.href;
|
|
1578
1568
|
}
|
|
1579
|
-
get saveRequests() {
|
|
1580
|
-
if (this._saveRequests === void 0) {
|
|
1581
|
-
return isServerSide() ? process.env.NODE_ENV === "test" : false;
|
|
1582
|
-
}
|
|
1583
|
-
return this._saveRequests;
|
|
1584
|
-
}
|
|
1585
|
-
set saveRequests(saveRequests) {
|
|
1586
|
-
this._saveRequests = saveRequests;
|
|
1587
|
-
}
|
|
1588
1569
|
get platform() {
|
|
1589
1570
|
return this.worker.platform;
|
|
1590
1571
|
}
|
|
@@ -1682,13 +1663,21 @@ var HttpInterceptorClient = class {
|
|
|
1682
1663
|
}
|
|
1683
1664
|
const responseDeclaration = await matchedHandler.applyResponseDeclaration(parsedRequest);
|
|
1684
1665
|
const response = HttpInterceptorWorker_default.createResponseFromDeclaration(request, responseDeclaration);
|
|
1685
|
-
if (this.
|
|
1666
|
+
if (this.requestSaving.enabled) {
|
|
1686
1667
|
const responseClone = response.clone();
|
|
1687
1668
|
const parsedResponse = await HttpInterceptorWorker_default.parseRawResponse(responseClone);
|
|
1688
1669
|
matchedHandler.saveInterceptedRequest(parsedRequest, parsedResponse);
|
|
1689
1670
|
}
|
|
1690
1671
|
return response;
|
|
1691
1672
|
}
|
|
1673
|
+
incrementNumberOfSavedRequests(increment) {
|
|
1674
|
+
this.numberOfSavedRequests = Math.max(this.numberOfSavedRequests + increment, 0);
|
|
1675
|
+
const exceedsSafeLimit = this.numberOfSavedRequests > this.requestSaving.safeLimit;
|
|
1676
|
+
if (increment > 0 && exceedsSafeLimit) {
|
|
1677
|
+
const error = new RequestSavingSafeLimitExceededError_default(this.numberOfSavedRequests, this.requestSaving.safeLimit);
|
|
1678
|
+
console.warn(error);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1692
1681
|
async findMatchedHandler(method, path, parsedRequest) {
|
|
1693
1682
|
const handlersByPath = this.handlerClientsByMethod[method].get(path) ?? [];
|
|
1694
1683
|
for (let handlerIndex = handlersByPath.length - 1; handlerIndex >= 0; handlerIndex--) {
|
|
@@ -2437,7 +2426,7 @@ var LocalHttpInterceptor = class {
|
|
|
2437
2426
|
baseURL,
|
|
2438
2427
|
Handler: LocalHttpRequestHandler_default,
|
|
2439
2428
|
onUnhandledRequest: options.onUnhandledRequest,
|
|
2440
|
-
|
|
2429
|
+
requestSaving: options.requestSaving
|
|
2441
2430
|
});
|
|
2442
2431
|
}
|
|
2443
2432
|
get type() {
|
|
@@ -2449,11 +2438,11 @@ var LocalHttpInterceptor = class {
|
|
|
2449
2438
|
set baseURL(baseURL) {
|
|
2450
2439
|
this.client.baseURL = new URL(baseURL);
|
|
2451
2440
|
}
|
|
2452
|
-
get
|
|
2453
|
-
return this.client.
|
|
2441
|
+
get requestSaving() {
|
|
2442
|
+
return this.client.requestSaving;
|
|
2454
2443
|
}
|
|
2455
|
-
set
|
|
2456
|
-
this.client.
|
|
2444
|
+
set requestSaving(requestSaving) {
|
|
2445
|
+
this.client.requestSaving = requestSaving;
|
|
2457
2446
|
}
|
|
2458
2447
|
get onUnhandledRequest() {
|
|
2459
2448
|
return this.client.onUnhandledRequest;
|
|
@@ -2527,7 +2516,7 @@ var RemoteHttpInterceptor = class {
|
|
|
2527
2516
|
baseURL,
|
|
2528
2517
|
Handler: RemoteHttpRequestHandler_default,
|
|
2529
2518
|
onUnhandledRequest: options.onUnhandledRequest,
|
|
2530
|
-
|
|
2519
|
+
requestSaving: options.requestSaving
|
|
2531
2520
|
});
|
|
2532
2521
|
}
|
|
2533
2522
|
get type() {
|
|
@@ -2539,11 +2528,11 @@ var RemoteHttpInterceptor = class {
|
|
|
2539
2528
|
set baseURL(baseURL) {
|
|
2540
2529
|
this.client.baseURL = new URL(baseURL);
|
|
2541
2530
|
}
|
|
2542
|
-
get
|
|
2543
|
-
return this.client.
|
|
2531
|
+
get requestSaving() {
|
|
2532
|
+
return this.client.requestSaving;
|
|
2544
2533
|
}
|
|
2545
|
-
set
|
|
2546
|
-
this.client.
|
|
2534
|
+
set requestSaving(requestSaving) {
|
|
2535
|
+
this.client.requestSaving = requestSaving;
|
|
2547
2536
|
}
|
|
2548
2537
|
get onUnhandledRequest() {
|
|
2549
2538
|
return this.client.onUnhandledRequest;
|
|
@@ -2631,55 +2620,6 @@ function createHttpInterceptor(options) {
|
|
|
2631
2620
|
throw new UnknownHttpInterceptorTypeError_default(type);
|
|
2632
2621
|
}
|
|
2633
2622
|
__name(createHttpInterceptor, "createHttpInterceptor");
|
|
2634
|
-
|
|
2635
|
-
// src/http/namespace/HttpInterceptorNamespace.ts
|
|
2636
|
-
var HttpInterceptorNamespaceDefault = class {
|
|
2637
|
-
static {
|
|
2638
|
-
__name(this, "HttpInterceptorNamespaceDefault");
|
|
2639
|
-
}
|
|
2640
|
-
local;
|
|
2641
|
-
remote;
|
|
2642
|
-
constructor() {
|
|
2643
|
-
const workerStore = new HttpInterceptorWorkerStore_default();
|
|
2644
|
-
this.local = {
|
|
2645
|
-
get onUnhandledRequest() {
|
|
2646
|
-
return workerStore.defaultOnUnhandledRequest("local");
|
|
2647
|
-
},
|
|
2648
|
-
set onUnhandledRequest(strategy) {
|
|
2649
|
-
workerStore.setDefaultOnUnhandledRequest("local", strategy);
|
|
2650
|
-
}
|
|
2651
|
-
};
|
|
2652
|
-
this.remote = {
|
|
2653
|
-
get onUnhandledRequest() {
|
|
2654
|
-
return workerStore.defaultOnUnhandledRequest("remote");
|
|
2655
|
-
},
|
|
2656
|
-
set onUnhandledRequest(strategy) {
|
|
2657
|
-
workerStore.setDefaultOnUnhandledRequest("remote", strategy);
|
|
2658
|
-
}
|
|
2659
|
-
};
|
|
2660
|
-
}
|
|
2661
|
-
};
|
|
2662
|
-
var HttpInterceptorNamespace = class {
|
|
2663
|
-
static {
|
|
2664
|
-
__name(this, "HttpInterceptorNamespace");
|
|
2665
|
-
}
|
|
2666
|
-
/**
|
|
2667
|
-
* Creates an HTTP interceptor.
|
|
2668
|
-
*
|
|
2669
|
-
* @param options The options for the interceptor.
|
|
2670
|
-
* @returns The created HTTP interceptor.
|
|
2671
|
-
* @throws {InvalidURLError} If the base URL is invalid.
|
|
2672
|
-
* @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
|
|
2673
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
|
|
2674
|
-
*/
|
|
2675
|
-
create = createHttpInterceptor;
|
|
2676
|
-
/** Default HTTP interceptor settings. */
|
|
2677
|
-
default = Object.freeze(new HttpInterceptorNamespaceDefault());
|
|
2678
|
-
};
|
|
2679
|
-
var HttpInterceptorNamespace_default = HttpInterceptorNamespace;
|
|
2680
|
-
|
|
2681
|
-
// src/http/index.ts
|
|
2682
|
-
var httpInterceptor = Object.freeze(new HttpInterceptorNamespace_default());
|
|
2683
2623
|
/* istanbul ignore else -- @preserve */
|
|
2684
2624
|
/* istanbul ignore next -- @preserve
|
|
2685
2625
|
* Ignoring because checking unknown platforms is not configured in our test setup. */
|
|
@@ -2699,11 +2639,12 @@ exports.DisabledRequestSavingError = DisabledRequestSavingError_default;
|
|
|
2699
2639
|
exports.InvalidFormDataError = InvalidFormDataError_default;
|
|
2700
2640
|
exports.InvalidJSONError = InvalidJSONError_default;
|
|
2701
2641
|
exports.NotRunningHttpInterceptorError = NotRunningHttpInterceptorError_default;
|
|
2642
|
+
exports.RequestSavingSafeLimitExceededError = RequestSavingSafeLimitExceededError_default;
|
|
2702
2643
|
exports.RunningHttpInterceptorError = RunningHttpInterceptorError_default;
|
|
2703
2644
|
exports.TimesCheckError = TimesCheckError_default;
|
|
2704
2645
|
exports.UnknownHttpInterceptorPlatformError = UnknownHttpInterceptorPlatformError_default;
|
|
2705
2646
|
exports.UnknownHttpInterceptorTypeError = UnknownHttpInterceptorTypeError_default;
|
|
2706
2647
|
exports.UnregisteredBrowserServiceWorkerError = UnregisteredBrowserServiceWorkerError_default;
|
|
2707
|
-
exports.
|
|
2648
|
+
exports.createHttpInterceptor = createHttpInterceptor;
|
|
2708
2649
|
//# sourceMappingURL=http.js.map
|
|
2709
2650
|
//# sourceMappingURL=http.js.map
|