@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.
- package/dist/{chunk-3XWHITKR.mjs → chunk-5ESJW32X.mjs} +90 -165
- package/dist/chunk-5ESJW32X.mjs.map +1 -0
- package/dist/{chunk-SWLQ2IF6.js → chunk-JIUQ7G6N.js} +90 -165
- package/dist/chunk-JIUQ7G6N.js.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +1 -12
- package/dist/http.js +182 -180
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +182 -180
- package/dist/http.mjs.map +1 -1
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/scripts/postinstall.mjs.map +1 -1
- package/dist/server.js +5 -5
- package/dist/server.mjs +1 -1
- package/package.json +4 -3
- package/src/http/interceptor/HttpInterceptorClient.ts +13 -7
- package/src/http/interceptor/HttpInterceptorStore.ts +4 -6
- package/src/http/interceptor/LocalHttpInterceptor.ts +6 -7
- package/src/http/interceptor/RemoteHttpInterceptor.ts +7 -11
- package/src/http/interceptor/types/options.ts +1 -1
- package/src/http/interceptor/types/requests.ts +1 -2
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +4 -5
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +5 -5
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +8 -8
- package/src/http/interceptorWorker/types/options.ts +1 -3
- package/src/http/interceptorWorker/types/requests.ts +1 -2
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +3 -2
- package/src/http/requestHandler/LocalHttpRequestHandler.ts +1 -2
- package/src/http/requestHandler/RemoteHttpRequestHandler.ts +1 -2
- package/src/http/requestHandler/errors/TimesCheckError.ts +2 -2
- package/src/http/requestHandler/types/public.ts +1 -2
- package/src/http/requestHandler/types/requests.ts +1 -2
- package/src/http/requestHandler/types/restrictions.ts +1 -2
- package/src/server/InterceptorServer.ts +6 -4
- package/src/utils/console.ts +3 -8
- package/src/utils/crypto.ts +1 -1
- package/src/utils/data.ts +0 -20
- package/src/utils/fetch.ts +0 -20
- package/src/utils/files.ts +5 -18
- package/src/utils/processes.ts +1 -1
- package/src/webSocket/WebSocketClient.ts +3 -5
- package/src/webSocket/WebSocketHandler.ts +1 -1
- package/src/webSocket/types.ts +1 -2
- package/dist/chunk-3XWHITKR.mjs.map +0 -1
- package/dist/chunk-SWLQ2IF6.js.map +0 -1
- package/src/types/arrays.d.ts +0 -4
- package/src/types/objects.d.ts +0 -14
- package/src/types/strings.d.ts +0 -9
- package/src/types/utils.ts +0 -28
- package/src/utils/imports.ts +0 -12
- package/src/utils/time.ts +0 -5
- package/src/utils/urls.ts +0 -138
package/dist/http.js
CHANGED
|
@@ -49,168 +49,62 @@ var UnknownHttpInterceptorTypeError = class extends TypeError {
|
|
|
49
49
|
};
|
|
50
50
|
var UnknownHttpInterceptorTypeError_default = UnknownHttpInterceptorTypeError;
|
|
51
51
|
|
|
52
|
-
//
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
super(`Invalid URL: '${url}'`);
|
|
59
|
-
this.name = "InvalidURL";
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var UnsupportedURLProtocolError = class extends TypeError {
|
|
63
|
-
static {
|
|
64
|
-
__name(this, "UnsupportedURLProtocolError");
|
|
65
|
-
}
|
|
66
|
-
constructor(protocol, availableProtocols) {
|
|
67
|
-
super(
|
|
68
|
-
`Unsupported URL protocol: '${protocol}'. The available options are ${availableProtocols.map((protocol2) => `'${protocol2}'`).join(", ")}`
|
|
69
|
-
);
|
|
70
|
-
this.name = "UnsupportedURLProtocolError";
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function createURLOrThrow(rawURL) {
|
|
74
|
-
try {
|
|
75
|
-
const url = new URL(rawURL);
|
|
76
|
-
Object.defineProperty(url, "raw", {
|
|
77
|
-
value: rawURL.toString(),
|
|
78
|
-
writable: false,
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: false
|
|
81
|
-
});
|
|
82
|
-
return url;
|
|
83
|
-
} catch {
|
|
84
|
-
throw new InvalidURLError(rawURL);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
__name(createURLOrThrow, "createURLOrThrow");
|
|
88
|
-
function excludeNonPathParams(url) {
|
|
52
|
+
// ../zimic-utils/dist/chunk-PAWJFY3S.mjs
|
|
53
|
+
var __defProp2 = Object.defineProperty;
|
|
54
|
+
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
|
55
|
+
|
|
56
|
+
// ../zimic-utils/dist/url/excludeURLParams.mjs
|
|
57
|
+
function excludeURLParams(url) {
|
|
89
58
|
url.hash = "";
|
|
90
59
|
url.search = "";
|
|
91
60
|
url.username = "";
|
|
92
61
|
url.password = "";
|
|
93
62
|
return url;
|
|
94
63
|
}
|
|
95
|
-
__name(
|
|
96
|
-
|
|
64
|
+
__name(excludeURLParams, "excludeURLParams");
|
|
65
|
+
__name2(excludeURLParams, "excludeURLParams");
|
|
66
|
+
var excludeURLParams_default = excludeURLParams;
|
|
67
|
+
|
|
68
|
+
// ../zimic-utils/dist/url/validateURLProtocol.mjs
|
|
69
|
+
var UnsupportedURLProtocolError = class extends TypeError {
|
|
97
70
|
static {
|
|
98
|
-
__name(this, "
|
|
71
|
+
__name(this, "UnsupportedURLProtocolError");
|
|
99
72
|
}
|
|
100
|
-
|
|
73
|
+
static {
|
|
74
|
+
__name2(this, "UnsupportedURLProtocolError");
|
|
75
|
+
}
|
|
76
|
+
constructor(protocol, availableProtocols) {
|
|
101
77
|
super(
|
|
102
|
-
`
|
|
78
|
+
`Unsupported URL protocol: '${protocol}'. The available options are ${availableProtocols.map((protocol2) => `'${protocol2}'`).join(", ")}`
|
|
103
79
|
);
|
|
104
|
-
this.name = "
|
|
80
|
+
this.name = "UnsupportedURLProtocolError";
|
|
105
81
|
}
|
|
106
82
|
};
|
|
107
|
-
|
|
108
|
-
function ensureUniquePathParams(url) {
|
|
109
|
-
const matches = url.matchAll(URL_PATH_PARAM_REGEX);
|
|
110
|
-
const uniqueParamNames = /* @__PURE__ */ new Set();
|
|
111
|
-
for (const match of matches) {
|
|
112
|
-
const paramName = match[1];
|
|
113
|
-
if (uniqueParamNames.has(paramName)) {
|
|
114
|
-
throw new DuplicatedPathParamError(url, paramName);
|
|
115
|
-
}
|
|
116
|
-
uniqueParamNames.add(paramName);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
__name(ensureUniquePathParams, "ensureUniquePathParams");
|
|
120
|
-
function createURL(rawURL, options = {}) {
|
|
121
|
-
const {
|
|
122
|
-
protocols,
|
|
123
|
-
excludeNonPathParams: shouldExcludeNonPathParams = false,
|
|
124
|
-
ensureUniquePathParams: shouldEnsureUniquePathParams = false
|
|
125
|
-
} = options;
|
|
126
|
-
const url = createURLOrThrow(rawURL);
|
|
83
|
+
function validateURLProtocol(url, protocols) {
|
|
127
84
|
const protocol = url.protocol.replace(/:$/, "");
|
|
128
|
-
if (
|
|
85
|
+
if (!protocols.includes(protocol)) {
|
|
129
86
|
throw new UnsupportedURLProtocolError(protocol, protocols);
|
|
130
87
|
}
|
|
131
|
-
if (shouldExcludeNonPathParams) {
|
|
132
|
-
excludeNonPathParams(url);
|
|
133
|
-
}
|
|
134
|
-
if (shouldEnsureUniquePathParams) {
|
|
135
|
-
ensureUniquePathParams(url.toString());
|
|
136
|
-
}
|
|
137
|
-
return url;
|
|
138
|
-
}
|
|
139
|
-
__name(createURL, "createURL");
|
|
140
|
-
function prepareURLForRegex(url) {
|
|
141
|
-
const encodedURL = encodeURI(url);
|
|
142
|
-
return encodedURL.replace(/([.()*?+$\\])/g, "\\$1");
|
|
143
|
-
}
|
|
144
|
-
__name(prepareURLForRegex, "prepareURLForRegex");
|
|
145
|
-
function createRegexFromURL(url) {
|
|
146
|
-
const urlWithReplacedPathParams = prepareURLForRegex(url).replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
|
|
147
|
-
return new RegExp(`^${urlWithReplacedPathParams}$`);
|
|
148
88
|
}
|
|
149
|
-
__name(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const isFirstPart = index === 0;
|
|
153
|
-
const isLastPart = index === parts.length - 1;
|
|
154
|
-
let partAsString = part.toString();
|
|
155
|
-
if (!isFirstPart) {
|
|
156
|
-
partAsString = partAsString.replace(/^\//, "");
|
|
157
|
-
}
|
|
158
|
-
if (!isLastPart) {
|
|
159
|
-
partAsString = partAsString.replace(/\/$/, "");
|
|
160
|
-
}
|
|
161
|
-
return partAsString;
|
|
162
|
-
}).filter((part) => part.length > 0).join("/");
|
|
163
|
-
}
|
|
164
|
-
__name(joinURL, "joinURL");
|
|
89
|
+
__name(validateURLProtocol, "validateURLProtocol");
|
|
90
|
+
__name2(validateURLProtocol, "validateURLProtocol");
|
|
91
|
+
var validateURLProtocol_default = validateURLProtocol;
|
|
165
92
|
|
|
166
|
-
//
|
|
167
|
-
function
|
|
168
|
-
return
|
|
93
|
+
// ../zimic-utils/dist/data/blobContains.mjs
|
|
94
|
+
async function blobContains(blob, otherBlob) {
|
|
95
|
+
return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
|
|
169
96
|
}
|
|
170
|
-
__name(
|
|
97
|
+
__name(blobContains, "blobContains");
|
|
98
|
+
__name2(blobContains, "blobContains");
|
|
99
|
+
var blobContains_default = blobContains;
|
|
171
100
|
|
|
172
|
-
//
|
|
101
|
+
// ../zimic-utils/dist/chunk-HVLEF6VF.mjs
|
|
173
102
|
async function blobEquals(blob, otherBlob) {
|
|
174
103
|
return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
|
|
175
104
|
}
|
|
176
105
|
__name(blobEquals, "blobEquals");
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
__name(blobContains, "blobContains");
|
|
181
|
-
function convertArrayBufferToBase64(buffer) {
|
|
182
|
-
if (isClientSide()) {
|
|
183
|
-
const bufferBytes = new Uint8Array(buffer);
|
|
184
|
-
const bufferAsStringArray = [];
|
|
185
|
-
for (const byte of bufferBytes) {
|
|
186
|
-
const byteCode = String.fromCharCode(byte);
|
|
187
|
-
bufferAsStringArray.push(byteCode);
|
|
188
|
-
}
|
|
189
|
-
const bufferAsString = bufferAsStringArray.join("");
|
|
190
|
-
return btoa(bufferAsString);
|
|
191
|
-
} else {
|
|
192
|
-
return Buffer.from(buffer).toString("base64");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
__name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
|
|
196
|
-
function convertBase64ToArrayBuffer(base64Value) {
|
|
197
|
-
if (isClientSide()) {
|
|
198
|
-
const bufferAsString = atob(base64Value);
|
|
199
|
-
const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
|
|
200
|
-
return array.buffer;
|
|
201
|
-
} else {
|
|
202
|
-
return Buffer.from(base64Value, "base64");
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
__name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
|
|
206
|
-
function isDefined(value) {
|
|
207
|
-
return value !== undefined && value !== null;
|
|
208
|
-
}
|
|
209
|
-
__name(isDefined, "isDefined");
|
|
210
|
-
function isNonEmpty(value) {
|
|
211
|
-
return isDefined(value) && value !== "";
|
|
212
|
-
}
|
|
213
|
-
__name(isNonEmpty, "isNonEmpty");
|
|
106
|
+
__name2(blobEquals, "blobEquals");
|
|
107
|
+
var blobEquals_default = blobEquals;
|
|
214
108
|
|
|
215
109
|
// src/utils/json.ts
|
|
216
110
|
function isPrimitiveJSONValue(value) {
|
|
@@ -315,17 +209,41 @@ var NoResponseDefinitionError = class extends TypeError {
|
|
|
315
209
|
};
|
|
316
210
|
var NoResponseDefinitionError_default = NoResponseDefinitionError;
|
|
317
211
|
|
|
318
|
-
//
|
|
212
|
+
// ../zimic-utils/dist/chunk-3O5CS47X.mjs
|
|
213
|
+
function isDefined(value) {
|
|
214
|
+
return value !== undefined && value !== null;
|
|
215
|
+
}
|
|
216
|
+
__name(isDefined, "isDefined");
|
|
217
|
+
__name2(isDefined, "isDefined");
|
|
218
|
+
var isDefined_default = isDefined;
|
|
219
|
+
|
|
220
|
+
// ../zimic-utils/dist/data/isNonEmpty.mjs
|
|
221
|
+
function isNonEmpty(value) {
|
|
222
|
+
return isDefined_default(value) && value !== "";
|
|
223
|
+
}
|
|
224
|
+
__name(isNonEmpty, "isNonEmpty");
|
|
225
|
+
__name2(isNonEmpty, "isNonEmpty");
|
|
226
|
+
var isNonEmpty_default = isNonEmpty;
|
|
227
|
+
|
|
228
|
+
// ../zimic-utils/dist/import/createCachedDynamicImport.mjs
|
|
319
229
|
function createCachedDynamicImport(importModuleDynamically) {
|
|
320
230
|
let cachedImportResult;
|
|
321
|
-
return /* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
|
|
231
|
+
return /* @__PURE__ */ __name2(/* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
|
|
322
232
|
if (cachedImportResult === undefined) {
|
|
323
233
|
cachedImportResult = await importModuleDynamically();
|
|
324
234
|
}
|
|
325
235
|
return cachedImportResult;
|
|
326
|
-
}, "importModuleDynamicallyWithCache");
|
|
236
|
+
}, "importModuleDynamicallyWithCache"), "importModuleDynamicallyWithCache");
|
|
327
237
|
}
|
|
328
238
|
__name(createCachedDynamicImport, "createCachedDynamicImport");
|
|
239
|
+
__name2(createCachedDynamicImport, "createCachedDynamicImport");
|
|
240
|
+
var createCachedDynamicImport_default = createCachedDynamicImport;
|
|
241
|
+
|
|
242
|
+
// src/utils/environment.ts
|
|
243
|
+
function isClientSide() {
|
|
244
|
+
return typeof window !== "undefined";
|
|
245
|
+
}
|
|
246
|
+
__name(isClientSide, "isClientSide");
|
|
329
247
|
function isGlobalFileAvailable() {
|
|
330
248
|
return globalThis.File !== undefined;
|
|
331
249
|
}
|
|
@@ -368,7 +286,7 @@ function stringifyValueToLog(value, options = {}) {
|
|
|
368
286
|
return fallback(value);
|
|
369
287
|
}
|
|
370
288
|
__name(stringifyValueToLog, "stringifyValueToLog");
|
|
371
|
-
var importUtil =
|
|
289
|
+
var importUtil = createCachedDynamicImport_default(() => import('util'));
|
|
372
290
|
async function formatValueToLog(value, options = {}) {
|
|
373
291
|
if (isClientSide()) {
|
|
374
292
|
return value;
|
|
@@ -389,7 +307,7 @@ __name(formatValueToLog, "formatValueToLog");
|
|
|
389
307
|
function logWithPrefix(messageOrMessages, options = {}) {
|
|
390
308
|
const { method = "log" } = options;
|
|
391
309
|
const messages = Array.isArray(messageOrMessages) ? messageOrMessages : [messageOrMessages];
|
|
392
|
-
console[method](chalk2__default.default.cyan("[zimic]"), ...messages);
|
|
310
|
+
console[method](chalk2__default.default.cyan("[@zimic/interceptor]"), ...messages);
|
|
393
311
|
}
|
|
394
312
|
__name(logWithPrefix, "logWithPrefix");
|
|
395
313
|
|
|
@@ -471,7 +389,7 @@ function createMessage(options) {
|
|
|
471
389
|
const messageHeader = createMessageHeader(options);
|
|
472
390
|
const messageDiffs = createMessageDiffs(options);
|
|
473
391
|
const messageFooter = createMessageFooter();
|
|
474
|
-
return [messageHeader, messageDiffs, messageFooter].filter(
|
|
392
|
+
return [messageHeader, messageDiffs, messageFooter].filter(isNonEmpty_default).join("\n\n");
|
|
475
393
|
}
|
|
476
394
|
__name(createMessage, "createMessage");
|
|
477
395
|
var TimesCheckError = class extends TypeError {
|
|
@@ -696,7 +614,7 @@ var HttpRequestHandlerClient = class {
|
|
|
696
614
|
diff: { expected: restrictionBody, received: body }
|
|
697
615
|
};
|
|
698
616
|
}
|
|
699
|
-
const matchesRestriction2 = restriction.exact ? await
|
|
617
|
+
const matchesRestriction2 = restriction.exact ? await blobEquals_default(body, restrictionBody) : await blobContains_default(body, restrictionBody);
|
|
700
618
|
return matchesRestriction2 ? { value: true } : {
|
|
701
619
|
value: false,
|
|
702
620
|
diff: { expected: restrictionBody, received: body }
|
|
@@ -797,6 +715,36 @@ var LocalHttpRequestHandler = class {
|
|
|
797
715
|
};
|
|
798
716
|
var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
|
|
799
717
|
|
|
718
|
+
// ../zimic-utils/dist/chunk-7MZYQWWC.mjs
|
|
719
|
+
var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
|
|
720
|
+
function createRegExpFromURL(url) {
|
|
721
|
+
URL_PATH_PARAM_REGEX.lastIndex = 0;
|
|
722
|
+
const urlWithReplacedPathParams = encodeURI(url).replace(/([.()*?+$\\])/g, "\\$1").replace(URL_PATH_PARAM_REGEX, "/(?<$1>[^/]+)").replace(/(\/+)$/, "(?:/+)?");
|
|
723
|
+
return new RegExp(`^${urlWithReplacedPathParams}$`);
|
|
724
|
+
}
|
|
725
|
+
__name(createRegExpFromURL, "createRegExpFromURL");
|
|
726
|
+
__name2(createRegExpFromURL, "createRegExpFromURL");
|
|
727
|
+
var createRegExpFromURL_default = createRegExpFromURL;
|
|
728
|
+
|
|
729
|
+
// ../zimic-utils/dist/url/joinURL.mjs
|
|
730
|
+
function joinURL(...parts) {
|
|
731
|
+
return parts.map((part, index) => {
|
|
732
|
+
const isFirstPart = index === 0;
|
|
733
|
+
const isLastPart = index === parts.length - 1;
|
|
734
|
+
let partAsString = part.toString();
|
|
735
|
+
if (!isFirstPart) {
|
|
736
|
+
partAsString = partAsString.replace(/^\//, "");
|
|
737
|
+
}
|
|
738
|
+
if (!isLastPart) {
|
|
739
|
+
partAsString = partAsString.replace(/\/$/, "");
|
|
740
|
+
}
|
|
741
|
+
return partAsString;
|
|
742
|
+
}).filter((part) => part.length > 0).join("/");
|
|
743
|
+
}
|
|
744
|
+
__name(joinURL, "joinURL");
|
|
745
|
+
__name2(joinURL, "joinURL");
|
|
746
|
+
var joinURL_default = joinURL;
|
|
747
|
+
|
|
800
748
|
// src/utils/arrays.ts
|
|
801
749
|
function removeArrayIndex(array, index) {
|
|
802
750
|
if (index >= 0 && index < array.length) {
|
|
@@ -985,7 +933,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
985
933
|
this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor)
|
|
986
934
|
]);
|
|
987
935
|
const candidatesOrPromises = [interceptorStrategy, defaultStrategy, globalDefaultStrategy];
|
|
988
|
-
const candidateStrategies = await Promise.all(candidatesOrPromises.filter(
|
|
936
|
+
const candidateStrategies = await Promise.all(candidatesOrPromises.filter(isDefined_default));
|
|
989
937
|
return candidateStrategies;
|
|
990
938
|
} catch (error) {
|
|
991
939
|
console.error(error);
|
|
@@ -1001,7 +949,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
1001
949
|
}
|
|
1002
950
|
findInterceptorByRequestBaseURL(request) {
|
|
1003
951
|
const interceptor = this.runningInterceptors.findLast((interceptor2) => {
|
|
1004
|
-
const baseURL = interceptor2.baseURL()
|
|
952
|
+
const baseURL = interceptor2.baseURL();
|
|
1005
953
|
return request.url.startsWith(baseURL);
|
|
1006
954
|
});
|
|
1007
955
|
return interceptor;
|
|
@@ -1048,7 +996,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
1048
996
|
const parsedBody = await this.parseRawBody(rawRequest);
|
|
1049
997
|
const headers = new http.HttpHeaders(rawRequest.headers);
|
|
1050
998
|
const pathParams = options.urlRegex ? this.parseRawPathParams(options.urlRegex, rawRequest) : {};
|
|
1051
|
-
const parsedURL =
|
|
999
|
+
const parsedURL = new URL(rawRequest.url);
|
|
1052
1000
|
const searchParams = new http.HttpSearchParams(parsedURL.searchParams);
|
|
1053
1001
|
const parsedRequest = new Proxy(rawRequest, {
|
|
1054
1002
|
has(target, property) {
|
|
@@ -1249,6 +1197,37 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
1249
1197
|
};
|
|
1250
1198
|
var HttpInterceptorWorker_default = HttpInterceptorWorker;
|
|
1251
1199
|
|
|
1200
|
+
// ../zimic-utils/dist/url/validateURLPathParams.mjs
|
|
1201
|
+
var DuplicatedPathParamError = class extends Error {
|
|
1202
|
+
static {
|
|
1203
|
+
__name(this, "DuplicatedPathParamError");
|
|
1204
|
+
}
|
|
1205
|
+
static {
|
|
1206
|
+
__name2(this, "DuplicatedPathParamError");
|
|
1207
|
+
}
|
|
1208
|
+
constructor(url, paramName) {
|
|
1209
|
+
super(
|
|
1210
|
+
`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.`
|
|
1211
|
+
);
|
|
1212
|
+
this.name = "DuplicatedPathParamError";
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
function validateURLPathParams(url) {
|
|
1216
|
+
URL_PATH_PARAM_REGEX.lastIndex = 0;
|
|
1217
|
+
const matches = url.toString().matchAll(URL_PATH_PARAM_REGEX);
|
|
1218
|
+
const uniqueParamNames = /* @__PURE__ */ new Set();
|
|
1219
|
+
for (const match of matches) {
|
|
1220
|
+
const paramName = match[1];
|
|
1221
|
+
if (uniqueParamNames.has(paramName)) {
|
|
1222
|
+
throw new DuplicatedPathParamError(url, paramName);
|
|
1223
|
+
}
|
|
1224
|
+
uniqueParamNames.add(paramName);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
__name(validateURLPathParams, "validateURLPathParams");
|
|
1228
|
+
__name2(validateURLPathParams, "validateURLPathParams");
|
|
1229
|
+
var validateURLPathParams_default = validateURLPathParams;
|
|
1230
|
+
|
|
1252
1231
|
// src/http/interceptor/errors/NotStartedHttpInterceptorError.ts
|
|
1253
1232
|
var NotStartedHttpInterceptorError = class extends Error {
|
|
1254
1233
|
static {
|
|
@@ -1400,10 +1379,9 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
1400
1379
|
use(interceptor, method, rawURL, createResponse) {
|
|
1401
1380
|
const internalWorker = this.internalWorkerOrThrow();
|
|
1402
1381
|
const lowercaseMethod = method.toLowerCase();
|
|
1403
|
-
const url =
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
});
|
|
1382
|
+
const url = new URL(rawURL);
|
|
1383
|
+
excludeURLParams_default(url);
|
|
1384
|
+
validateURLPathParams_default(url);
|
|
1407
1385
|
const httpHandler = msw.http[lowercaseMethod](url.toString(), async (context) => {
|
|
1408
1386
|
const request = context.request;
|
|
1409
1387
|
const requestClone = request.clone();
|
|
@@ -1600,7 +1578,11 @@ var HttpInterceptorClient = class {
|
|
|
1600
1578
|
this._shouldSaveRequests = options.saveRequests ?? false;
|
|
1601
1579
|
}
|
|
1602
1580
|
baseURL() {
|
|
1603
|
-
|
|
1581
|
+
const baseURL = this._baseURL;
|
|
1582
|
+
if (baseURL.href === `${baseURL.origin}/`) {
|
|
1583
|
+
return baseURL.origin;
|
|
1584
|
+
}
|
|
1585
|
+
return baseURL.toString();
|
|
1604
1586
|
}
|
|
1605
1587
|
platform() {
|
|
1606
1588
|
return this.worker.platform();
|
|
@@ -1683,8 +1665,8 @@ var HttpInterceptorClient = class {
|
|
|
1683
1665
|
return;
|
|
1684
1666
|
}
|
|
1685
1667
|
this.handlerClientsByMethod[handler.method()].set(handler.path(), handlerClients);
|
|
1686
|
-
const url =
|
|
1687
|
-
const urlRegex =
|
|
1668
|
+
const url = joinURL_default(this.baseURL(), handler.path());
|
|
1669
|
+
const urlRegex = createRegExpFromURL_default(url);
|
|
1688
1670
|
const registrationResult = this.worker.use(this, handler.method(), url, async (context) => {
|
|
1689
1671
|
const response = await this.handleInterceptedRequest(
|
|
1690
1672
|
urlRegex,
|
|
@@ -1768,11 +1750,38 @@ var HttpInterceptorClient = class {
|
|
|
1768
1750
|
var HttpInterceptorClient_default = HttpInterceptorClient;
|
|
1769
1751
|
|
|
1770
1752
|
// src/utils/crypto.ts
|
|
1771
|
-
var importCrypto =
|
|
1753
|
+
var importCrypto = createCachedDynamicImport_default(async () => {
|
|
1772
1754
|
const globalCrypto = globalThis.crypto;
|
|
1773
1755
|
return globalCrypto ?? await import('crypto');
|
|
1774
1756
|
});
|
|
1775
1757
|
|
|
1758
|
+
// src/utils/data.ts
|
|
1759
|
+
function convertArrayBufferToBase64(buffer) {
|
|
1760
|
+
if (isClientSide()) {
|
|
1761
|
+
const bufferBytes = new Uint8Array(buffer);
|
|
1762
|
+
const bufferAsStringArray = [];
|
|
1763
|
+
for (const byte of bufferBytes) {
|
|
1764
|
+
const byteCode = String.fromCharCode(byte);
|
|
1765
|
+
bufferAsStringArray.push(byteCode);
|
|
1766
|
+
}
|
|
1767
|
+
const bufferAsString = bufferAsStringArray.join("");
|
|
1768
|
+
return btoa(bufferAsString);
|
|
1769
|
+
} else {
|
|
1770
|
+
return Buffer.from(buffer).toString("base64");
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
__name(convertArrayBufferToBase64, "convertArrayBufferToBase64");
|
|
1774
|
+
function convertBase64ToArrayBuffer(base64Value) {
|
|
1775
|
+
if (isClientSide()) {
|
|
1776
|
+
const bufferAsString = atob(base64Value);
|
|
1777
|
+
const array = Uint8Array.from(bufferAsString, (character) => character.charCodeAt(0));
|
|
1778
|
+
return array.buffer;
|
|
1779
|
+
} else {
|
|
1780
|
+
return Buffer.from(base64Value, "base64");
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
__name(convertBase64ToArrayBuffer, "convertBase64ToArrayBuffer");
|
|
1784
|
+
|
|
1776
1785
|
// src/utils/fetch.ts
|
|
1777
1786
|
function deserializeRequest(serializedRequest) {
|
|
1778
1787
|
const deserializedBody = serializedRequest.body ? convertBase64ToArrayBuffer(serializedRequest.body) : null;
|
|
@@ -2186,9 +2195,8 @@ var WebSocketClient = class extends WebSocketHandler_default {
|
|
|
2186
2195
|
socketTimeout: options.socketTimeout,
|
|
2187
2196
|
messageTimeout: options.messageTimeout
|
|
2188
2197
|
});
|
|
2189
|
-
this.url =
|
|
2190
|
-
|
|
2191
|
-
});
|
|
2198
|
+
this.url = new URL(options.url);
|
|
2199
|
+
validateURLProtocol_default(this.url, SUPPORTED_WEB_SOCKET_PROTOCOLS);
|
|
2192
2200
|
}
|
|
2193
2201
|
isRunning() {
|
|
2194
2202
|
return this.socket !== undefined && this.socket.readyState === this.socket.OPEN;
|
|
@@ -2229,7 +2237,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
2229
2237
|
});
|
|
2230
2238
|
}
|
|
2231
2239
|
deriveWebSocketServerURL(serverURL) {
|
|
2232
|
-
const webSocketServerURL =
|
|
2240
|
+
const webSocketServerURL = new URL(serverURL);
|
|
2233
2241
|
webSocketServerURL.protocol = serverURL.protocol.replace(/^http(s)?:$/, "ws$1:");
|
|
2234
2242
|
return webSocketServerURL;
|
|
2235
2243
|
}
|
|
@@ -2293,14 +2301,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
|
|
|
2293
2301
|
throw new NotStartedHttpInterceptorError_default();
|
|
2294
2302
|
}
|
|
2295
2303
|
const crypto = await importCrypto();
|
|
2296
|
-
const url =
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
});
|
|
2304
|
+
const url = new URL(rawURL);
|
|
2305
|
+
excludeURLParams_default(url);
|
|
2306
|
+
validateURLPathParams_default(url);
|
|
2300
2307
|
const handler = {
|
|
2301
2308
|
id: crypto.randomUUID(),
|
|
2302
2309
|
url: {
|
|
2303
|
-
base: interceptor.baseURL()
|
|
2310
|
+
base: interceptor.baseURL(),
|
|
2304
2311
|
full: url.toString()
|
|
2305
2312
|
},
|
|
2306
2313
|
method,
|
|
@@ -2441,10 +2448,9 @@ var LocalHttpInterceptor = class {
|
|
|
2441
2448
|
_client;
|
|
2442
2449
|
constructor(options) {
|
|
2443
2450
|
this.type = options.type;
|
|
2444
|
-
const baseURL =
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
});
|
|
2451
|
+
const baseURL = new URL(options.baseURL);
|
|
2452
|
+
validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
|
|
2453
|
+
excludeURLParams_default(baseURL);
|
|
2448
2454
|
const worker = this.store.getOrCreateLocalWorker({});
|
|
2449
2455
|
this._client = new HttpInterceptorClient_default({
|
|
2450
2456
|
worker,
|
|
@@ -2459,7 +2465,7 @@ var LocalHttpInterceptor = class {
|
|
|
2459
2465
|
return this._client;
|
|
2460
2466
|
}
|
|
2461
2467
|
baseURL() {
|
|
2462
|
-
return this._client.baseURL()
|
|
2468
|
+
return this._client.baseURL();
|
|
2463
2469
|
}
|
|
2464
2470
|
platform() {
|
|
2465
2471
|
return this._client.platform();
|
|
@@ -2520,14 +2526,10 @@ var RemoteHttpInterceptor = class {
|
|
|
2520
2526
|
_client;
|
|
2521
2527
|
constructor(options) {
|
|
2522
2528
|
this.type = options.type;
|
|
2523
|
-
const baseURL =
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
const serverURL = createURL(baseURL.origin, {
|
|
2528
|
-
protocols: SUPPORTED_BASE_URL_PROTOCOLS,
|
|
2529
|
-
excludeNonPathParams: true
|
|
2530
|
-
});
|
|
2529
|
+
const baseURL = new URL(options.baseURL);
|
|
2530
|
+
validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
|
|
2531
|
+
excludeURLParams_default(baseURL);
|
|
2532
|
+
const serverURL = new URL(baseURL.origin);
|
|
2531
2533
|
const worker = this.store.getOrCreateRemoteWorker({ serverURL });
|
|
2532
2534
|
this._client = new HttpInterceptorClient_default({
|
|
2533
2535
|
worker,
|
|
@@ -2542,7 +2544,7 @@ var RemoteHttpInterceptor = class {
|
|
|
2542
2544
|
return this._client;
|
|
2543
2545
|
}
|
|
2544
2546
|
baseURL() {
|
|
2545
|
-
return this._client.baseURL()
|
|
2547
|
+
return this._client.baseURL();
|
|
2546
2548
|
}
|
|
2547
2549
|
platform() {
|
|
2548
2550
|
return this._client.platform();
|