@zimic/interceptor 0.16.0-canary.0 → 0.16.0-canary.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/{chunk-6TSSHQW5.mjs → chunk-2RNFR6TF.mjs} +6 -47
- package/dist/chunk-2RNFR6TF.mjs.map +1 -0
- package/dist/{chunk-R2ROSKU4.js → chunk-D7CDDSQE.js} +6 -47
- package/dist/chunk-D7CDDSQE.js.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +1 -35
- package/dist/http.js +5 -74
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +5 -74
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/src/http/index.ts +0 -1
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +4 -29
- package/src/http/namespace/HttpInterceptorNamespace.ts +0 -60
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +1 -1
- 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/dist/http.d.ts
CHANGED
|
@@ -1165,38 +1165,6 @@ declare function createHttpInterceptor<Schema extends HttpSchema>(options: Local
|
|
|
1165
1165
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
|
|
1166
1166
|
declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
|
|
1167
1167
|
|
|
1168
|
-
/** Default HTTP interceptor settings. */
|
|
1169
|
-
declare class HttpInterceptorNamespaceDefault {
|
|
1170
|
-
local: {
|
|
1171
|
-
/**
|
|
1172
|
-
* Gets or sets the default strategy for local unhandled requests. If a request does not start with the base URL of
|
|
1173
|
-
* any local interceptors, this strategy will be used. If a function is provided, it will be called with the
|
|
1174
|
-
* unhandled request.
|
|
1175
|
-
*
|
|
1176
|
-
* You can override this default for specific interceptors by using `onUnhandledRequest` in
|
|
1177
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)`}.
|
|
1178
|
-
*
|
|
1179
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
1180
|
-
*/
|
|
1181
|
-
get onUnhandledRequest(): UnhandledRequestStrategy.Local;
|
|
1182
|
-
set onUnhandledRequest(strategy: UnhandledRequestStrategy.Local);
|
|
1183
|
-
};
|
|
1184
|
-
remote: {
|
|
1185
|
-
/**
|
|
1186
|
-
* Gets or sets the default strategy for remote unhandled requests. If a request does not start with the base URL of
|
|
1187
|
-
* any remote interceptors, this strategy will be used. If a function is provided, it will be called with the
|
|
1188
|
-
* unhandled request.
|
|
1189
|
-
*
|
|
1190
|
-
* You can override this default for specific interceptors by using `onUnhandledRequest` in
|
|
1191
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)`}.
|
|
1192
|
-
*
|
|
1193
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
1194
|
-
*/
|
|
1195
|
-
get onUnhandledRequest(): UnhandledRequestStrategy.Remote;
|
|
1196
|
-
set onUnhandledRequest(strategy: UnhandledRequestStrategy.Remote);
|
|
1197
|
-
};
|
|
1198
|
-
constructor();
|
|
1199
|
-
}
|
|
1200
1168
|
/**
|
|
1201
1169
|
* A namespace of interceptor resources for mocking HTTP requests.
|
|
1202
1170
|
*
|
|
@@ -1213,8 +1181,6 @@ declare class HttpInterceptorNamespace {
|
|
|
1213
1181
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
|
|
1214
1182
|
*/
|
|
1215
1183
|
create: typeof createHttpInterceptor;
|
|
1216
|
-
/** Default HTTP interceptor settings. */
|
|
1217
|
-
default: Readonly<HttpInterceptorNamespaceDefault>;
|
|
1218
1184
|
}
|
|
1219
1185
|
|
|
1220
1186
|
/**
|
|
@@ -1344,4 +1310,4 @@ type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInte
|
|
|
1344
1310
|
*/
|
|
1345
1311
|
declare const httpInterceptor: Readonly<HttpInterceptorNamespace>;
|
|
1346
1312
|
|
|
1347
|
-
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace,
|
|
1313
|
+
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, httpInterceptor };
|
package/dist/http.js
CHANGED
|
@@ -153,7 +153,7 @@ var DisabledRequestSavingError = class extends TypeError {
|
|
|
153
153
|
}
|
|
154
154
|
constructor() {
|
|
155
155
|
super(
|
|
156
|
-
"Intercepted requests are not saved
|
|
156
|
+
"Intercepted requests are not being saved. Did you forget to use `saveRequests: true` when creating the interceptor?\n\nLearn more: https://github.com/zimicjs/zimic/wiki/api\u2010zimic\u2010interceptor\u2010http#saving-requests"
|
|
157
157
|
);
|
|
158
158
|
this.name = "DisabledRequestSavingError";
|
|
159
159
|
}
|
|
@@ -811,29 +811,6 @@ var InvalidJSONError = class extends SyntaxError {
|
|
|
811
811
|
};
|
|
812
812
|
var InvalidJSONError_default = InvalidJSONError;
|
|
813
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
814
|
// src/http/interceptorWorker/HttpInterceptorWorker.ts
|
|
838
815
|
var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
839
816
|
static {
|
|
@@ -843,7 +820,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
843
820
|
isRunning = false;
|
|
844
821
|
startingPromise;
|
|
845
822
|
stoppingPromise;
|
|
846
|
-
store = new HttpInterceptorWorkerStore_default();
|
|
847
823
|
runningInterceptors = [];
|
|
848
824
|
async sharedStart(internalStart) {
|
|
849
825
|
if (this.isRunning) {
|
|
@@ -902,24 +878,18 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
902
878
|
);
|
|
903
879
|
}
|
|
904
880
|
async getUnhandledRequestStrategyCandidates(request, interceptorType) {
|
|
905
|
-
const globalDefaultStrategy =
|
|
881
|
+
const globalDefaultStrategy = DEFAULT_UNHANDLED_REQUEST_STRATEGY[interceptorType];
|
|
906
882
|
try {
|
|
907
883
|
const interceptor = this.findInterceptorByRequestBaseURL(request);
|
|
908
884
|
if (!interceptor) {
|
|
909
885
|
return [];
|
|
910
886
|
}
|
|
911
887
|
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;
|
|
888
|
+
const interceptorStrategy = await this.getInterceptorUnhandledRequestStrategy(requestClone, interceptor);
|
|
889
|
+
return [interceptorStrategy, globalDefaultStrategy].filter(isDefined_default);
|
|
919
890
|
} catch (error) {
|
|
920
891
|
console.error(error);
|
|
921
|
-
|
|
922
|
-
return candidateStrategies;
|
|
892
|
+
return [globalDefaultStrategy];
|
|
923
893
|
}
|
|
924
894
|
}
|
|
925
895
|
registerRunningInterceptor(interceptor) {
|
|
@@ -934,17 +904,6 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
|
|
|
934
904
|
});
|
|
935
905
|
return interceptor;
|
|
936
906
|
}
|
|
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
907
|
async getInterceptorUnhandledRequestStrategy(request, interceptor) {
|
|
949
908
|
if (typeof interceptor.onUnhandledRequest === "function") {
|
|
950
909
|
const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
|
|
@@ -2633,32 +2592,6 @@ function createHttpInterceptor(options) {
|
|
|
2633
2592
|
__name(createHttpInterceptor, "createHttpInterceptor");
|
|
2634
2593
|
|
|
2635
2594
|
// 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
2595
|
var HttpInterceptorNamespace = class {
|
|
2663
2596
|
static {
|
|
2664
2597
|
__name(this, "HttpInterceptorNamespace");
|
|
@@ -2673,8 +2606,6 @@ var HttpInterceptorNamespace = class {
|
|
|
2673
2606
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
|
|
2674
2607
|
*/
|
|
2675
2608
|
create = createHttpInterceptor;
|
|
2676
|
-
/** Default HTTP interceptor settings. */
|
|
2677
|
-
default = Object.freeze(new HttpInterceptorNamespaceDefault());
|
|
2678
2609
|
};
|
|
2679
2610
|
var HttpInterceptorNamespace_default = HttpInterceptorNamespace;
|
|
2680
2611
|
|