@zimic/interceptor 0.16.0-canary.11 → 0.16.0-canary.3
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 +2 -1
- package/dist/{chunk-NTRC2S4I.mjs → chunk-2RNFR6TF.mjs} +267 -249
- package/dist/chunk-2RNFR6TF.mjs.map +1 -0
- package/dist/{chunk-O6ZIPCUJ.js → chunk-D7CDDSQE.js} +268 -250
- package/dist/chunk-D7CDDSQE.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 +141 -180
- package/dist/http.js +69 -102
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +69 -101
- package/dist/http.mjs.map +1 -1
- package/dist/server.d.ts +46 -20
- package/dist/server.js +7 -7
- package/dist/server.mjs +1 -1
- package/package.json +11 -11
- package/src/cli/browser/init.ts +2 -2
- package/src/cli/server/start.ts +2 -2
- package/src/http/index.ts +2 -5
- package/src/http/interceptor/HttpInterceptorClient.ts +15 -30
- package/src/http/interceptor/LocalHttpInterceptor.ts +8 -8
- package/src/http/interceptor/RemoteHttpInterceptor.ts +8 -8
- package/src/http/interceptor/types/options.ts +10 -3
- package/src/http/interceptor/types/public.ts +12 -44
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +2 -2
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +5 -15
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +1 -1
- package/src/http/requestHandler/errors/TimesCheckError.ts +14 -15
- package/src/http/requestHandler/types/public.ts +8 -16
- package/src/server/index.ts +11 -1
- package/src/server/namespace/InterceptorServerNamespace.ts +21 -0
- package/src/utils/console.ts +2 -2
- package/dist/chunk-NTRC2S4I.mjs.map +0 -1
- package/dist/chunk-O6ZIPCUJ.js.map +0 -1
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +0 -22
|
@@ -1,258 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkWCQVDF3K_js = require('./chunk-WCQVDF3K.js');
|
|
4
|
-
var http = require('@zimic/http');
|
|
5
4
|
var server = require('@whatwg-node/server');
|
|
6
5
|
var http$1 = require('http');
|
|
7
|
-
var
|
|
6
|
+
var http = require('@zimic/http');
|
|
7
|
+
var chalk2 = require('chalk');
|
|
8
8
|
var ClientSocket = require('isomorphic-ws');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var chalk2__default = /*#__PURE__*/_interopDefault(chalk2);
|
|
13
13
|
var ClientSocket__default = /*#__PURE__*/_interopDefault(ClientSocket);
|
|
14
14
|
|
|
15
|
-
// src/server/errors/RunningInterceptorServerError.ts
|
|
16
|
-
var RunningInterceptorServerError = class extends Error {
|
|
17
|
-
static {
|
|
18
|
-
chunkWCQVDF3K_js.__name(this, "RunningInterceptorServerError");
|
|
19
|
-
}
|
|
20
|
-
constructor(additionalMessage) {
|
|
21
|
-
super(`The interceptor server is running.${additionalMessage}`);
|
|
22
|
-
this.name = "RunningInterceptorServerError";
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var RunningInterceptorServerError_default = RunningInterceptorServerError;
|
|
26
|
-
|
|
27
|
-
// src/server/errors/NotRunningInterceptorServerError.ts
|
|
28
|
-
var NotRunningInterceptorServerError = class extends Error {
|
|
29
|
-
static {
|
|
30
|
-
chunkWCQVDF3K_js.__name(this, "NotRunningInterceptorServerError");
|
|
31
|
-
}
|
|
32
|
-
constructor() {
|
|
33
|
-
super("The interceptor server is not running. Did you forget to start it?");
|
|
34
|
-
this.name = "NotRunningInterceptorServerError";
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var NotRunningInterceptorServerError_default = NotRunningInterceptorServerError;
|
|
38
|
-
var HttpServerTimeoutError = class extends Error {
|
|
39
|
-
static {
|
|
40
|
-
chunkWCQVDF3K_js.__name(this, "HttpServerTimeoutError");
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var HttpServerStartTimeoutError = class extends HttpServerTimeoutError {
|
|
44
|
-
static {
|
|
45
|
-
chunkWCQVDF3K_js.__name(this, "HttpServerStartTimeoutError");
|
|
46
|
-
}
|
|
47
|
-
constructor(reachedTimeout) {
|
|
48
|
-
super(`HTTP server start timed out after ${reachedTimeout}ms.`);
|
|
49
|
-
this.name = "HttpServerStartTimeout";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var HttpServerStopTimeoutError = class extends HttpServerTimeoutError {
|
|
53
|
-
static {
|
|
54
|
-
chunkWCQVDF3K_js.__name(this, "HttpServerStopTimeoutError");
|
|
55
|
-
}
|
|
56
|
-
constructor(reachedTimeout) {
|
|
57
|
-
super(`HTTP server stop timed out after ${reachedTimeout}ms.`);
|
|
58
|
-
this.name = "HttpServerStopTimeout";
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT = 60 * 1e3;
|
|
62
|
-
async function startHttpServer(server, options = {}) {
|
|
63
|
-
const { hostname, port, timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
|
|
64
|
-
await new Promise((resolve, reject) => {
|
|
65
|
-
function handleStartError(error) {
|
|
66
|
-
server.off("listening", handleStartSuccess);
|
|
67
|
-
reject(error);
|
|
68
|
-
}
|
|
69
|
-
chunkWCQVDF3K_js.__name(handleStartError, "handleStartError");
|
|
70
|
-
const startTimeout = setTimeout(() => {
|
|
71
|
-
const timeoutError = new HttpServerStartTimeoutError(timeoutDuration);
|
|
72
|
-
handleStartError(timeoutError);
|
|
73
|
-
}, timeoutDuration);
|
|
74
|
-
function handleStartSuccess() {
|
|
75
|
-
server.off("error", handleStartError);
|
|
76
|
-
clearTimeout(startTimeout);
|
|
77
|
-
resolve();
|
|
78
|
-
}
|
|
79
|
-
chunkWCQVDF3K_js.__name(handleStartSuccess, "handleStartSuccess");
|
|
80
|
-
server.once("error", handleStartError);
|
|
81
|
-
server.listen(port, hostname, handleStartSuccess);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
chunkWCQVDF3K_js.__name(startHttpServer, "startHttpServer");
|
|
85
|
-
async function stopHttpServer(server, options = {}) {
|
|
86
|
-
const { timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
|
|
87
|
-
if (!server.listening) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
await new Promise((resolve, reject) => {
|
|
91
|
-
const stopTimeout = setTimeout(() => {
|
|
92
|
-
const timeoutError = new HttpServerStopTimeoutError(timeoutDuration);
|
|
93
|
-
reject(timeoutError);
|
|
94
|
-
}, timeoutDuration);
|
|
95
|
-
server.close((error) => {
|
|
96
|
-
clearTimeout(stopTimeout);
|
|
97
|
-
if (error) {
|
|
98
|
-
reject(error);
|
|
99
|
-
} else {
|
|
100
|
-
resolve();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
server.closeAllConnections();
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
chunkWCQVDF3K_js.__name(stopHttpServer, "stopHttpServer");
|
|
107
|
-
function getHttpServerPort(server) {
|
|
108
|
-
const address = server.address();
|
|
109
|
-
if (typeof address === "string") {
|
|
110
|
-
return void 0;
|
|
111
|
-
} else {
|
|
112
|
-
return address?.port;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
chunkWCQVDF3K_js.__name(getHttpServerPort, "getHttpServerPort");
|
|
116
|
-
function methodCanHaveResponseBody(method) {
|
|
117
|
-
const methodsToCompare = http.HTTP_METHODS_WITH_RESPONSE_BODY;
|
|
118
|
-
return methodsToCompare.includes(method);
|
|
119
|
-
}
|
|
120
|
-
chunkWCQVDF3K_js.__name(methodCanHaveResponseBody, "methodCanHaveResponseBody");
|
|
121
|
-
|
|
122
|
-
// src/utils/webSocket.ts
|
|
123
|
-
var WebSocketTimeoutError = class extends Error {
|
|
124
|
-
static {
|
|
125
|
-
chunkWCQVDF3K_js.__name(this, "WebSocketTimeoutError");
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var WebSocketOpenTimeoutError = class extends WebSocketTimeoutError {
|
|
129
|
-
static {
|
|
130
|
-
chunkWCQVDF3K_js.__name(this, "WebSocketOpenTimeoutError");
|
|
131
|
-
}
|
|
132
|
-
constructor(reachedTimeout) {
|
|
133
|
-
super(`Web socket open timed out after ${reachedTimeout}ms.`);
|
|
134
|
-
this.name = "WebSocketOpenTimeout";
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var WebSocketMessageTimeoutError = class extends WebSocketTimeoutError {
|
|
138
|
-
static {
|
|
139
|
-
chunkWCQVDF3K_js.__name(this, "WebSocketMessageTimeoutError");
|
|
140
|
-
}
|
|
141
|
-
constructor(reachedTimeout) {
|
|
142
|
-
super(`Web socket message timed out after ${reachedTimeout}ms.`);
|
|
143
|
-
this.name = "WebSocketMessageTimeout";
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
var WebSocketMessageAbortError = class extends WebSocketTimeoutError {
|
|
147
|
-
static {
|
|
148
|
-
chunkWCQVDF3K_js.__name(this, "WebSocketMessageAbortError");
|
|
149
|
-
}
|
|
150
|
-
constructor() {
|
|
151
|
-
super("Web socket message was aborted.");
|
|
152
|
-
this.name = "WebSocketMessageAbortError";
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
var WebSocketCloseTimeoutError = class extends WebSocketTimeoutError {
|
|
156
|
-
static {
|
|
157
|
-
chunkWCQVDF3K_js.__name(this, "WebSocketCloseTimeoutError");
|
|
158
|
-
}
|
|
159
|
-
constructor(reachedTimeout) {
|
|
160
|
-
super(`Web socket close timed out after ${reachedTimeout}ms.`);
|
|
161
|
-
this.name = "WebSocketCloseTimeout";
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT = 60 * 1e3;
|
|
165
|
-
var DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT = 3 * 60 * 1e3;
|
|
166
|
-
async function waitForOpenClientSocket(socket, options = {}) {
|
|
167
|
-
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
168
|
-
const isAlreadyOpen = socket.readyState === socket.OPEN;
|
|
169
|
-
if (isAlreadyOpen) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
await new Promise((resolve, reject) => {
|
|
173
|
-
function handleOpenError(error) {
|
|
174
|
-
socket.removeEventListener("open", handleOpenSuccess);
|
|
175
|
-
reject(error);
|
|
176
|
-
}
|
|
177
|
-
chunkWCQVDF3K_js.__name(handleOpenError, "handleOpenError");
|
|
178
|
-
const openTimeout = setTimeout(() => {
|
|
179
|
-
const timeoutError = new WebSocketOpenTimeoutError(timeoutDuration);
|
|
180
|
-
handleOpenError(timeoutError);
|
|
181
|
-
}, timeoutDuration);
|
|
182
|
-
function handleOpenSuccess() {
|
|
183
|
-
socket.removeEventListener("error", handleOpenError);
|
|
184
|
-
clearTimeout(openTimeout);
|
|
185
|
-
resolve();
|
|
186
|
-
}
|
|
187
|
-
chunkWCQVDF3K_js.__name(handleOpenSuccess, "handleOpenSuccess");
|
|
188
|
-
socket.addEventListener("open", handleOpenSuccess);
|
|
189
|
-
socket.addEventListener("error", handleOpenError);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
chunkWCQVDF3K_js.__name(waitForOpenClientSocket, "waitForOpenClientSocket");
|
|
193
|
-
async function closeClientSocket(socket, options = {}) {
|
|
194
|
-
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
195
|
-
const isAlreadyClosed = socket.readyState === socket.CLOSED;
|
|
196
|
-
if (isAlreadyClosed) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
await new Promise((resolve, reject) => {
|
|
200
|
-
function handleCloseError(error) {
|
|
201
|
-
socket.removeEventListener("close", handleCloseSuccess);
|
|
202
|
-
reject(error);
|
|
203
|
-
}
|
|
204
|
-
chunkWCQVDF3K_js.__name(handleCloseError, "handleCloseError");
|
|
205
|
-
const closeTimeout = setTimeout(() => {
|
|
206
|
-
const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
|
|
207
|
-
handleCloseError(timeoutError);
|
|
208
|
-
}, timeoutDuration);
|
|
209
|
-
function handleCloseSuccess() {
|
|
210
|
-
socket.removeEventListener("error", handleCloseError);
|
|
211
|
-
clearTimeout(closeTimeout);
|
|
212
|
-
resolve();
|
|
213
|
-
}
|
|
214
|
-
chunkWCQVDF3K_js.__name(handleCloseSuccess, "handleCloseSuccess");
|
|
215
|
-
socket.addEventListener("error", handleCloseError);
|
|
216
|
-
socket.addEventListener("close", handleCloseSuccess);
|
|
217
|
-
socket.close();
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
chunkWCQVDF3K_js.__name(closeClientSocket, "closeClientSocket");
|
|
221
|
-
async function closeServerSocket(socket, options = {}) {
|
|
222
|
-
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
223
|
-
await new Promise((resolve, reject) => {
|
|
224
|
-
const closeTimeout = setTimeout(() => {
|
|
225
|
-
const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
|
|
226
|
-
reject(timeoutError);
|
|
227
|
-
}, timeoutDuration);
|
|
228
|
-
for (const client of socket.clients) {
|
|
229
|
-
client.terminate();
|
|
230
|
-
}
|
|
231
|
-
socket.close((error) => {
|
|
232
|
-
clearTimeout(closeTimeout);
|
|
233
|
-
if (error) {
|
|
234
|
-
reject(error);
|
|
235
|
-
} else {
|
|
236
|
-
resolve();
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
chunkWCQVDF3K_js.__name(closeServerSocket, "closeServerSocket");
|
|
242
|
-
|
|
243
|
-
// src/server/constants.ts
|
|
244
|
-
var ALLOWED_ACCESS_CONTROL_HTTP_METHODS = http.HTTP_METHODS.join(",");
|
|
245
|
-
var DEFAULT_ACCESS_CONTROL_HEADERS = Object.freeze({
|
|
246
|
-
"access-control-allow-origin": "*",
|
|
247
|
-
"access-control-allow-methods": ALLOWED_ACCESS_CONTROL_HTTP_METHODS,
|
|
248
|
-
"access-control-allow-headers": "*",
|
|
249
|
-
"access-control-expose-headers": "*",
|
|
250
|
-
"access-control-max-age": ""
|
|
251
|
-
});
|
|
252
|
-
var DEFAULT_PREFLIGHT_STATUS_CODE = 204;
|
|
253
|
-
var DEFAULT_HOSTNAME = "localhost";
|
|
254
|
-
var DEFAULT_LOG_UNHANDLED_REQUESTS = true;
|
|
255
|
-
|
|
256
15
|
// ../zimic-utils/dist/chunk-PAWJFY3S.mjs
|
|
257
16
|
var __defProp = Object.defineProperty;
|
|
258
17
|
var __name2 = /* @__PURE__ */ chunkWCQVDF3K_js.__name((target, value) => __defProp(target, "name", { value, configurable: true }), "__name");
|
|
@@ -352,9 +111,92 @@ chunkWCQVDF3K_js.__name(formatValueToLog, "formatValueToLog");
|
|
|
352
111
|
function logWithPrefix(messageOrMessages, options = {}) {
|
|
353
112
|
const { method = "log" } = options;
|
|
354
113
|
const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
|
|
355
|
-
console[method](
|
|
114
|
+
console[method](chalk2__default.default.cyan("[@zimic/interceptor]"), ...messages);
|
|
356
115
|
}
|
|
357
116
|
chunkWCQVDF3K_js.__name(logWithPrefix, "logWithPrefix");
|
|
117
|
+
var HttpServerTimeoutError = class extends Error {
|
|
118
|
+
static {
|
|
119
|
+
chunkWCQVDF3K_js.__name(this, "HttpServerTimeoutError");
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var HttpServerStartTimeoutError = class extends HttpServerTimeoutError {
|
|
123
|
+
static {
|
|
124
|
+
chunkWCQVDF3K_js.__name(this, "HttpServerStartTimeoutError");
|
|
125
|
+
}
|
|
126
|
+
constructor(reachedTimeout) {
|
|
127
|
+
super(`HTTP server start timed out after ${reachedTimeout}ms.`);
|
|
128
|
+
this.name = "HttpServerStartTimeout";
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var HttpServerStopTimeoutError = class extends HttpServerTimeoutError {
|
|
132
|
+
static {
|
|
133
|
+
chunkWCQVDF3K_js.__name(this, "HttpServerStopTimeoutError");
|
|
134
|
+
}
|
|
135
|
+
constructor(reachedTimeout) {
|
|
136
|
+
super(`HTTP server stop timed out after ${reachedTimeout}ms.`);
|
|
137
|
+
this.name = "HttpServerStopTimeout";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT = 60 * 1e3;
|
|
141
|
+
async function startHttpServer(server, options = {}) {
|
|
142
|
+
const { hostname, port, timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
|
|
143
|
+
await new Promise((resolve, reject) => {
|
|
144
|
+
function handleStartError(error) {
|
|
145
|
+
server.off("listening", handleStartSuccess);
|
|
146
|
+
reject(error);
|
|
147
|
+
}
|
|
148
|
+
chunkWCQVDF3K_js.__name(handleStartError, "handleStartError");
|
|
149
|
+
const startTimeout = setTimeout(() => {
|
|
150
|
+
const timeoutError = new HttpServerStartTimeoutError(timeoutDuration);
|
|
151
|
+
handleStartError(timeoutError);
|
|
152
|
+
}, timeoutDuration);
|
|
153
|
+
function handleStartSuccess() {
|
|
154
|
+
server.off("error", handleStartError);
|
|
155
|
+
clearTimeout(startTimeout);
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
158
|
+
chunkWCQVDF3K_js.__name(handleStartSuccess, "handleStartSuccess");
|
|
159
|
+
server.once("error", handleStartError);
|
|
160
|
+
server.listen(port, hostname, handleStartSuccess);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
chunkWCQVDF3K_js.__name(startHttpServer, "startHttpServer");
|
|
164
|
+
async function stopHttpServer(server, options = {}) {
|
|
165
|
+
const { timeout: timeoutDuration = DEFAULT_HTTP_SERVER_LIFECYCLE_TIMEOUT } = options;
|
|
166
|
+
if (!server.listening) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
await new Promise((resolve, reject) => {
|
|
170
|
+
const stopTimeout = setTimeout(() => {
|
|
171
|
+
const timeoutError = new HttpServerStopTimeoutError(timeoutDuration);
|
|
172
|
+
reject(timeoutError);
|
|
173
|
+
}, timeoutDuration);
|
|
174
|
+
server.close((error) => {
|
|
175
|
+
clearTimeout(stopTimeout);
|
|
176
|
+
if (error) {
|
|
177
|
+
reject(error);
|
|
178
|
+
} else {
|
|
179
|
+
resolve();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
server.closeAllConnections();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
chunkWCQVDF3K_js.__name(stopHttpServer, "stopHttpServer");
|
|
186
|
+
function getHttpServerPort(server) {
|
|
187
|
+
const address = server.address();
|
|
188
|
+
if (typeof address === "string") {
|
|
189
|
+
return void 0;
|
|
190
|
+
} else {
|
|
191
|
+
return address?.port;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
chunkWCQVDF3K_js.__name(getHttpServerPort, "getHttpServerPort");
|
|
195
|
+
function methodCanHaveResponseBody(method) {
|
|
196
|
+
const methodsToCompare = http.HTTP_METHODS_WITH_RESPONSE_BODY;
|
|
197
|
+
return methodsToCompare.includes(method);
|
|
198
|
+
}
|
|
199
|
+
chunkWCQVDF3K_js.__name(methodCanHaveResponseBody, "methodCanHaveResponseBody");
|
|
358
200
|
|
|
359
201
|
// src/http/requestHandler/types/requests.ts
|
|
360
202
|
var HTTP_INTERCEPTOR_REQUEST_HIDDEN_PROPERTIES = Object.freeze(
|
|
@@ -716,7 +558,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
716
558
|
]);
|
|
717
559
|
logWithPrefix(
|
|
718
560
|
[
|
|
719
|
-
`${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ?
|
|
561
|
+
`${action === "bypass" ? "Warning:" : "Error:"} Request was not handled and was ${action === "bypass" ? chalk2__default.default.yellow("bypassed") : chalk2__default.default.red("rejected")}.
|
|
720
562
|
|
|
721
563
|
`,
|
|
722
564
|
`${request.method} ${request.url}`,
|
|
@@ -791,6 +633,127 @@ function deserializeResponse(serializedResponse) {
|
|
|
791
633
|
}
|
|
792
634
|
chunkWCQVDF3K_js.__name(deserializeResponse, "deserializeResponse");
|
|
793
635
|
|
|
636
|
+
// src/utils/webSocket.ts
|
|
637
|
+
var WebSocketTimeoutError = class extends Error {
|
|
638
|
+
static {
|
|
639
|
+
chunkWCQVDF3K_js.__name(this, "WebSocketTimeoutError");
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
var WebSocketOpenTimeoutError = class extends WebSocketTimeoutError {
|
|
643
|
+
static {
|
|
644
|
+
chunkWCQVDF3K_js.__name(this, "WebSocketOpenTimeoutError");
|
|
645
|
+
}
|
|
646
|
+
constructor(reachedTimeout) {
|
|
647
|
+
super(`Web socket open timed out after ${reachedTimeout}ms.`);
|
|
648
|
+
this.name = "WebSocketOpenTimeout";
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
var WebSocketMessageTimeoutError = class extends WebSocketTimeoutError {
|
|
652
|
+
static {
|
|
653
|
+
chunkWCQVDF3K_js.__name(this, "WebSocketMessageTimeoutError");
|
|
654
|
+
}
|
|
655
|
+
constructor(reachedTimeout) {
|
|
656
|
+
super(`Web socket message timed out after ${reachedTimeout}ms.`);
|
|
657
|
+
this.name = "WebSocketMessageTimeout";
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
var WebSocketMessageAbortError = class extends WebSocketTimeoutError {
|
|
661
|
+
static {
|
|
662
|
+
chunkWCQVDF3K_js.__name(this, "WebSocketMessageAbortError");
|
|
663
|
+
}
|
|
664
|
+
constructor() {
|
|
665
|
+
super("Web socket message was aborted.");
|
|
666
|
+
this.name = "WebSocketMessageAbortError";
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
var WebSocketCloseTimeoutError = class extends WebSocketTimeoutError {
|
|
670
|
+
static {
|
|
671
|
+
chunkWCQVDF3K_js.__name(this, "WebSocketCloseTimeoutError");
|
|
672
|
+
}
|
|
673
|
+
constructor(reachedTimeout) {
|
|
674
|
+
super(`Web socket close timed out after ${reachedTimeout}ms.`);
|
|
675
|
+
this.name = "WebSocketCloseTimeout";
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
var DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT = 60 * 1e3;
|
|
679
|
+
var DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT = 3 * 60 * 1e3;
|
|
680
|
+
async function waitForOpenClientSocket(socket, options = {}) {
|
|
681
|
+
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
682
|
+
const isAlreadyOpen = socket.readyState === socket.OPEN;
|
|
683
|
+
if (isAlreadyOpen) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
await new Promise((resolve, reject) => {
|
|
687
|
+
function handleOpenError(error) {
|
|
688
|
+
socket.removeEventListener("open", handleOpenSuccess);
|
|
689
|
+
reject(error);
|
|
690
|
+
}
|
|
691
|
+
chunkWCQVDF3K_js.__name(handleOpenError, "handleOpenError");
|
|
692
|
+
const openTimeout = setTimeout(() => {
|
|
693
|
+
const timeoutError = new WebSocketOpenTimeoutError(timeoutDuration);
|
|
694
|
+
handleOpenError(timeoutError);
|
|
695
|
+
}, timeoutDuration);
|
|
696
|
+
function handleOpenSuccess() {
|
|
697
|
+
socket.removeEventListener("error", handleOpenError);
|
|
698
|
+
clearTimeout(openTimeout);
|
|
699
|
+
resolve();
|
|
700
|
+
}
|
|
701
|
+
chunkWCQVDF3K_js.__name(handleOpenSuccess, "handleOpenSuccess");
|
|
702
|
+
socket.addEventListener("open", handleOpenSuccess);
|
|
703
|
+
socket.addEventListener("error", handleOpenError);
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
chunkWCQVDF3K_js.__name(waitForOpenClientSocket, "waitForOpenClientSocket");
|
|
707
|
+
async function closeClientSocket(socket, options = {}) {
|
|
708
|
+
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
709
|
+
const isAlreadyClosed = socket.readyState === socket.CLOSED;
|
|
710
|
+
if (isAlreadyClosed) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
await new Promise((resolve, reject) => {
|
|
714
|
+
function handleCloseError(error) {
|
|
715
|
+
socket.removeEventListener("close", handleCloseSuccess);
|
|
716
|
+
reject(error);
|
|
717
|
+
}
|
|
718
|
+
chunkWCQVDF3K_js.__name(handleCloseError, "handleCloseError");
|
|
719
|
+
const closeTimeout = setTimeout(() => {
|
|
720
|
+
const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
|
|
721
|
+
handleCloseError(timeoutError);
|
|
722
|
+
}, timeoutDuration);
|
|
723
|
+
function handleCloseSuccess() {
|
|
724
|
+
socket.removeEventListener("error", handleCloseError);
|
|
725
|
+
clearTimeout(closeTimeout);
|
|
726
|
+
resolve();
|
|
727
|
+
}
|
|
728
|
+
chunkWCQVDF3K_js.__name(handleCloseSuccess, "handleCloseSuccess");
|
|
729
|
+
socket.addEventListener("error", handleCloseError);
|
|
730
|
+
socket.addEventListener("close", handleCloseSuccess);
|
|
731
|
+
socket.close();
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
chunkWCQVDF3K_js.__name(closeClientSocket, "closeClientSocket");
|
|
735
|
+
async function closeServerSocket(socket, options = {}) {
|
|
736
|
+
const { timeout: timeoutDuration = DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT } = options;
|
|
737
|
+
await new Promise((resolve, reject) => {
|
|
738
|
+
const closeTimeout = setTimeout(() => {
|
|
739
|
+
const timeoutError = new WebSocketCloseTimeoutError(timeoutDuration);
|
|
740
|
+
reject(timeoutError);
|
|
741
|
+
}, timeoutDuration);
|
|
742
|
+
for (const client of socket.clients) {
|
|
743
|
+
client.terminate();
|
|
744
|
+
}
|
|
745
|
+
socket.close((error) => {
|
|
746
|
+
clearTimeout(closeTimeout);
|
|
747
|
+
if (error) {
|
|
748
|
+
reject(error);
|
|
749
|
+
} else {
|
|
750
|
+
resolve();
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
chunkWCQVDF3K_js.__name(closeServerSocket, "closeServerSocket");
|
|
756
|
+
|
|
794
757
|
// src/utils/crypto.ts
|
|
795
758
|
var importCrypto = createCachedDynamicImport_default(async () => {
|
|
796
759
|
const globalCrypto = globalThis.crypto;
|
|
@@ -1109,6 +1072,41 @@ var WebSocketServer = class extends WebSocketHandler_default {
|
|
|
1109
1072
|
}
|
|
1110
1073
|
};
|
|
1111
1074
|
var WebSocketServer_default = WebSocketServer;
|
|
1075
|
+
var ALLOWED_ACCESS_CONTROL_HTTP_METHODS = http.HTTP_METHODS.join(",");
|
|
1076
|
+
var DEFAULT_ACCESS_CONTROL_HEADERS = Object.freeze({
|
|
1077
|
+
"access-control-allow-origin": "*",
|
|
1078
|
+
"access-control-allow-methods": ALLOWED_ACCESS_CONTROL_HTTP_METHODS,
|
|
1079
|
+
"access-control-allow-headers": "*",
|
|
1080
|
+
"access-control-expose-headers": "*",
|
|
1081
|
+
"access-control-max-age": ""
|
|
1082
|
+
});
|
|
1083
|
+
var DEFAULT_PREFLIGHT_STATUS_CODE = 204;
|
|
1084
|
+
var DEFAULT_HOSTNAME = "localhost";
|
|
1085
|
+
var DEFAULT_LOG_UNHANDLED_REQUESTS = true;
|
|
1086
|
+
|
|
1087
|
+
// src/server/errors/NotRunningInterceptorServerError.ts
|
|
1088
|
+
var NotRunningInterceptorServerError = class extends Error {
|
|
1089
|
+
static {
|
|
1090
|
+
chunkWCQVDF3K_js.__name(this, "NotRunningInterceptorServerError");
|
|
1091
|
+
}
|
|
1092
|
+
constructor() {
|
|
1093
|
+
super("The interceptor server is not running. Did you forget to start it?");
|
|
1094
|
+
this.name = "NotRunningInterceptorServerError";
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
var NotRunningInterceptorServerError_default = NotRunningInterceptorServerError;
|
|
1098
|
+
|
|
1099
|
+
// src/server/errors/RunningInterceptorServerError.ts
|
|
1100
|
+
var RunningInterceptorServerError = class extends Error {
|
|
1101
|
+
static {
|
|
1102
|
+
chunkWCQVDF3K_js.__name(this, "RunningInterceptorServerError");
|
|
1103
|
+
}
|
|
1104
|
+
constructor(additionalMessage) {
|
|
1105
|
+
super(`The interceptor server is running.${additionalMessage}`);
|
|
1106
|
+
this.name = "RunningInterceptorServerError";
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
var RunningInterceptorServerError_default = RunningInterceptorServerError;
|
|
1112
1110
|
|
|
1113
1111
|
// src/server/utils/fetch.ts
|
|
1114
1112
|
async function getFetchAPI() {
|
|
@@ -1393,7 +1391,26 @@ function createInterceptorServer(options = {}) {
|
|
|
1393
1391
|
return new InterceptorServer_default(options);
|
|
1394
1392
|
}
|
|
1395
1393
|
chunkWCQVDF3K_js.__name(createInterceptorServer, "createInterceptorServer");
|
|
1396
|
-
|
|
1394
|
+
|
|
1395
|
+
// src/server/namespace/InterceptorServerNamespace.ts
|
|
1396
|
+
var InterceptorServerNamespace = class {
|
|
1397
|
+
static {
|
|
1398
|
+
chunkWCQVDF3K_js.__name(this, "InterceptorServerNamespace");
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Creates an {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}.
|
|
1402
|
+
*
|
|
1403
|
+
* @param options The options to create the server.
|
|
1404
|
+
* @returns The created server.
|
|
1405
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server-programmatic-usage `zimic-interceptor server` programmatic usage}
|
|
1406
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors Remote HTTP Interceptors} .
|
|
1407
|
+
*/
|
|
1408
|
+
create = createInterceptorServer;
|
|
1409
|
+
};
|
|
1410
|
+
var InterceptorServerNamespace_default = InterceptorServerNamespace;
|
|
1411
|
+
|
|
1412
|
+
// src/server/index.ts
|
|
1413
|
+
var interceptorServer = Object.freeze(new InterceptorServerNamespace_default());
|
|
1397
1414
|
/* istanbul ignore if -- @preserve
|
|
1398
1415
|
* This is expected not to happen since the servers are not stopped unless they are running. */
|
|
1399
1416
|
/* istanbul ignore if -- @preserve
|
|
@@ -1409,6 +1426,7 @@ chunkWCQVDF3K_js.__name(createInterceptorServer, "createInterceptorServer");
|
|
|
1409
1426
|
/* istanbul ignore next -- @preserve
|
|
1410
1427
|
* Reply listeners are always present when notified in normal conditions. If they were not present, the request
|
|
1411
1428
|
* would reach a timeout and not be responded. The empty set serves as a fallback. */
|
|
1429
|
+
/* istanbul ignore next -- @preserve */
|
|
1412
1430
|
/* istanbul ignore if -- @preserve
|
|
1413
1431
|
* The HTTP server is initialized before using this method in normal conditions. */
|
|
1414
1432
|
/* istanbul ignore if -- @preserve
|
|
@@ -1424,7 +1442,7 @@ exports.DEFAULT_PREFLIGHT_STATUS_CODE = DEFAULT_PREFLIGHT_STATUS_CODE;
|
|
|
1424
1442
|
exports.NotRunningInterceptorServerError_default = NotRunningInterceptorServerError_default;
|
|
1425
1443
|
exports.RunningInterceptorServerError_default = RunningInterceptorServerError_default;
|
|
1426
1444
|
exports.createCachedDynamicImport_default = createCachedDynamicImport_default;
|
|
1427
|
-
exports.
|
|
1445
|
+
exports.interceptorServer = interceptorServer;
|
|
1428
1446
|
exports.logWithPrefix = logWithPrefix;
|
|
1429
|
-
//# sourceMappingURL=chunk-
|
|
1430
|
-
//# sourceMappingURL=chunk-
|
|
1447
|
+
//# sourceMappingURL=chunk-D7CDDSQE.js.map
|
|
1448
|
+
//# sourceMappingURL=chunk-D7CDDSQE.js.map
|