@zimic/interceptor 1.0.2-canary.1 → 1.0.2
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/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/http.js +26 -26
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +26 -26
- package/dist/http.mjs.map +1 -1
- package/package.json +4 -4
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +28 -26
- package/src/http/requestHandler/types/restrictions.ts +1 -1
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"api",
|
|
15
15
|
"static"
|
|
16
16
|
],
|
|
17
|
-
"version": "1.0.2
|
|
17
|
+
"version": "1.0.2",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/zimicjs/zimic.git",
|
|
@@ -105,12 +105,12 @@
|
|
|
105
105
|
"vitest": "^3.2.4",
|
|
106
106
|
"@zimic/eslint-config-node": "0.0.0",
|
|
107
107
|
"@zimic/lint-staged-config": "0.0.0",
|
|
108
|
-
"@zimic/
|
|
109
|
-
"@zimic/
|
|
108
|
+
"@zimic/tsconfig": "0.0.0",
|
|
109
|
+
"@zimic/utils": "0.0.0"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
112
|
"typescript": ">=5.0.0",
|
|
113
|
-
"@zimic/http": "^1.0.0 || 1.0.2
|
|
113
|
+
"@zimic/http": "^1.0.0 || 1.0.2"
|
|
114
114
|
},
|
|
115
115
|
"peerDependenciesMeta": {
|
|
116
116
|
"typescript": {
|
|
@@ -163,7 +163,7 @@ class HttpRequestHandlerClient<
|
|
|
163
163
|
|
|
164
164
|
const restrictionsMatch = await this.matchesRequestRestrictions(request);
|
|
165
165
|
|
|
166
|
-
if (restrictionsMatch.
|
|
166
|
+
if (restrictionsMatch.success) {
|
|
167
167
|
this.numberOfMatchedRequests++;
|
|
168
168
|
} else {
|
|
169
169
|
const shouldSaveUnmatchedGroup =
|
|
@@ -181,7 +181,7 @@ class HttpRequestHandlerClient<
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
const isWithinLimits = this.numberOfMatchedRequests <= this.limits.numberOfRequests.max;
|
|
184
|
-
return restrictionsMatch.
|
|
184
|
+
return restrictionsMatch.success && isWithinLimits;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
private async matchesRequestRestrictions(
|
|
@@ -193,7 +193,7 @@ class HttpRequestHandlerClient<
|
|
|
193
193
|
|
|
194
194
|
if (!matchesComputedRestriction) {
|
|
195
195
|
return {
|
|
196
|
-
|
|
196
|
+
success: false,
|
|
197
197
|
diff: { computed: { expected: true, received: false } },
|
|
198
198
|
};
|
|
199
199
|
}
|
|
@@ -206,11 +206,13 @@ class HttpRequestHandlerClient<
|
|
|
206
206
|
const matchesBodyRestrictions = await this.matchesRequestBodyRestrictions(request, restriction);
|
|
207
207
|
|
|
208
208
|
const matchesRestriction =
|
|
209
|
-
matchesHeadersRestrictions.
|
|
209
|
+
matchesHeadersRestrictions.success &&
|
|
210
|
+
matchesSearchParamsRestrictions.success &&
|
|
211
|
+
matchesBodyRestrictions.success;
|
|
210
212
|
|
|
211
213
|
if (!matchesRestriction) {
|
|
212
214
|
return {
|
|
213
|
-
|
|
215
|
+
success: false,
|
|
214
216
|
diff: {
|
|
215
217
|
headers: matchesHeadersRestrictions.diff,
|
|
216
218
|
searchParams: matchesSearchParamsRestrictions.diff,
|
|
@@ -220,7 +222,7 @@ class HttpRequestHandlerClient<
|
|
|
220
222
|
}
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
return {
|
|
225
|
+
return { success: true };
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
private matchesRequestHeadersRestrictions(
|
|
@@ -229,7 +231,7 @@ class HttpRequestHandlerClient<
|
|
|
229
231
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
232
|
): RestrictionMatchResult<RestrictionDiff<HttpHeaders<any>>> {
|
|
231
233
|
if (restriction.headers === undefined) {
|
|
232
|
-
return {
|
|
234
|
+
return { success: true };
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
const restrictedHeaders = new HttpHeaders(
|
|
@@ -241,9 +243,9 @@ class HttpRequestHandlerClient<
|
|
|
241
243
|
: request.headers.contains(restrictedHeaders);
|
|
242
244
|
|
|
243
245
|
return matchesRestriction
|
|
244
|
-
? {
|
|
246
|
+
? { success: true }
|
|
245
247
|
: {
|
|
246
|
-
|
|
248
|
+
success: false,
|
|
247
249
|
diff: { expected: restrictedHeaders, received: request.headers },
|
|
248
250
|
};
|
|
249
251
|
}
|
|
@@ -254,7 +256,7 @@ class HttpRequestHandlerClient<
|
|
|
254
256
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
257
|
): RestrictionMatchResult<RestrictionDiff<HttpSearchParams<any>>> {
|
|
256
258
|
if (restriction.searchParams === undefined) {
|
|
257
|
-
return {
|
|
259
|
+
return { success: true };
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
const restrictedSearchParams = new HttpSearchParams(
|
|
@@ -266,9 +268,9 @@ class HttpRequestHandlerClient<
|
|
|
266
268
|
: request.searchParams.contains(restrictedSearchParams);
|
|
267
269
|
|
|
268
270
|
return matchesRestriction
|
|
269
|
-
? {
|
|
271
|
+
? { success: true }
|
|
270
272
|
: {
|
|
271
|
-
|
|
273
|
+
success: false,
|
|
272
274
|
diff: { expected: restrictedSearchParams, received: request.searchParams },
|
|
273
275
|
};
|
|
274
276
|
}
|
|
@@ -278,7 +280,7 @@ class HttpRequestHandlerClient<
|
|
|
278
280
|
restriction: HttpRequestHandlerStaticRestriction<Schema, Method, Path>,
|
|
279
281
|
): Promise<RestrictionMatchResult<RestrictionDiff<unknown>>> {
|
|
280
282
|
if (restriction.body === undefined) {
|
|
281
|
-
return {
|
|
283
|
+
return { success: true };
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
const body = request.body as unknown;
|
|
@@ -288,9 +290,9 @@ class HttpRequestHandlerClient<
|
|
|
288
290
|
const matchesRestriction = restriction.exact ? body === restrictionBody : body.includes(restrictionBody);
|
|
289
291
|
|
|
290
292
|
return matchesRestriction
|
|
291
|
-
? {
|
|
293
|
+
? { success: true }
|
|
292
294
|
: {
|
|
293
|
-
|
|
295
|
+
success: false,
|
|
294
296
|
diff: { expected: restrictionBody, received: body },
|
|
295
297
|
};
|
|
296
298
|
}
|
|
@@ -298,7 +300,7 @@ class HttpRequestHandlerClient<
|
|
|
298
300
|
if (restrictionBody instanceof HttpFormData) {
|
|
299
301
|
if (!(body instanceof HttpFormData)) {
|
|
300
302
|
return {
|
|
301
|
-
|
|
303
|
+
success: false,
|
|
302
304
|
diff: { expected: restrictionBody, received: body },
|
|
303
305
|
};
|
|
304
306
|
}
|
|
@@ -308,9 +310,9 @@ class HttpRequestHandlerClient<
|
|
|
308
310
|
: await body.contains(restrictionBody);
|
|
309
311
|
|
|
310
312
|
return matchesRestriction
|
|
311
|
-
? {
|
|
313
|
+
? { success: true }
|
|
312
314
|
: {
|
|
313
|
-
|
|
315
|
+
success: false,
|
|
314
316
|
diff: { expected: restrictionBody, received: body },
|
|
315
317
|
};
|
|
316
318
|
}
|
|
@@ -318,7 +320,7 @@ class HttpRequestHandlerClient<
|
|
|
318
320
|
if (restrictionBody instanceof HttpSearchParams) {
|
|
319
321
|
if (!(body instanceof HttpSearchParams)) {
|
|
320
322
|
return {
|
|
321
|
-
|
|
323
|
+
success: false,
|
|
322
324
|
diff: { expected: restrictionBody, received: body },
|
|
323
325
|
};
|
|
324
326
|
}
|
|
@@ -326,9 +328,9 @@ class HttpRequestHandlerClient<
|
|
|
326
328
|
const matchesRestriction = restriction.exact ? body.equals(restrictionBody) : body.contains(restrictionBody);
|
|
327
329
|
|
|
328
330
|
return matchesRestriction
|
|
329
|
-
? {
|
|
331
|
+
? { success: true }
|
|
330
332
|
: {
|
|
331
|
-
|
|
333
|
+
success: false,
|
|
332
334
|
diff: { expected: restrictionBody, received: body },
|
|
333
335
|
};
|
|
334
336
|
}
|
|
@@ -340,7 +342,7 @@ class HttpRequestHandlerClient<
|
|
|
340
342
|
) {
|
|
341
343
|
if (!(body instanceof Blob)) {
|
|
342
344
|
return {
|
|
343
|
-
|
|
345
|
+
success: false,
|
|
344
346
|
diff: { expected: restrictionBody, received: body },
|
|
345
347
|
};
|
|
346
348
|
}
|
|
@@ -361,9 +363,9 @@ class HttpRequestHandlerClient<
|
|
|
361
363
|
const matchesRestriction = await blobEquals(body, restrictionBodyAsBlob);
|
|
362
364
|
|
|
363
365
|
return matchesRestriction
|
|
364
|
-
? {
|
|
366
|
+
? { success: true }
|
|
365
367
|
: {
|
|
366
|
-
|
|
368
|
+
success: false,
|
|
367
369
|
diff: { expected: restrictionBody, received: body },
|
|
368
370
|
};
|
|
369
371
|
}
|
|
@@ -373,9 +375,9 @@ class HttpRequestHandlerClient<
|
|
|
373
375
|
: jsonContains(request.body, restriction.body);
|
|
374
376
|
|
|
375
377
|
return matchesRestriction
|
|
376
|
-
? {
|
|
378
|
+
? { success: true }
|
|
377
379
|
: {
|
|
378
|
-
|
|
380
|
+
success: false,
|
|
379
381
|
diff: { expected: restrictionBody, received: body },
|
|
380
382
|
};
|
|
381
383
|
}
|
|
@@ -102,7 +102,7 @@ export interface RestrictionDiff<Value> {
|
|
|
102
102
|
received: Value;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export type RestrictionMatchResult<Value> = {
|
|
105
|
+
export type RestrictionMatchResult<Value> = { success: true; diff?: undefined } | { success: false; diff: Value };
|
|
106
106
|
|
|
107
107
|
export interface RestrictionDiffs {
|
|
108
108
|
computed?: RestrictionDiff<boolean>;
|