@zimic/interceptor 0.19.1-canary.1 → 0.19.1-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/dist/{chunk-6PRFBMY7.mjs → chunk-7BR57OM2.mjs} +3 -3
- package/dist/chunk-7BR57OM2.mjs.map +1 -0
- package/dist/{chunk-3NJLJSD6.js → chunk-QB2A2272.js} +3 -3
- package/dist/chunk-QB2A2272.js.map +1 -0
- package/dist/cli.js +20 -20
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +262 -467
- package/dist/http.js +5 -5
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +5 -5
- package/dist/http.mjs.map +1 -1
- package/dist/scripts/postinstall.js +1 -17
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/scripts/postinstall.mjs +2 -17
- package/dist/scripts/postinstall.mjs.map +1 -1
- package/dist/server.d.ts +14 -15
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +8 -8
- package/src/cli/server/start.ts +1 -1
- package/src/cli/server/token/create.ts +1 -1
- package/src/http/interceptor/errors/NotRunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +2 -2
- package/src/http/interceptor/errors/RunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
- package/src/http/interceptor/factory.ts +1 -9
- package/src/http/interceptor/types/options.ts +32 -132
- package/src/http/interceptor/types/public.ts +153 -236
- package/src/http/interceptor/types/schema.ts +2 -3
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +1 -1
- package/src/http/interceptorWorker/errors/UnregisteredBrowserServiceWorkerError.ts +2 -2
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +2 -2
- package/src/http/requestHandler/errors/TimesCheckError.ts +1 -1
- package/src/http/requestHandler/types/public.ts +60 -73
- package/src/http/requestHandler/types/restrictions.ts +6 -6
- package/src/server/errors/InvalidInterceptorTokenError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenFileError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenValueError.ts +1 -1
- package/src/server/errors/RunningInterceptorServerError.ts +1 -1
- package/src/server/factory.ts +3 -3
- package/src/server/types/options.ts +2 -3
- package/src/server/types/public.ts +8 -8
- package/dist/chunk-3NJLJSD6.js.map +0 -1
- package/dist/chunk-6PRFBMY7.mjs.map +0 -1
|
@@ -3,192 +3,92 @@ import { PossiblePromise } from '@zimic/utils/types';
|
|
|
3
3
|
import { HttpInterceptorRequestSaving } from './public';
|
|
4
4
|
import { UnhandledHttpInterceptorRequest } from './requests';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* An type of an HTTP interceptor.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
|
|
10
|
-
*/
|
|
6
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptortype `interceptor.type` API reference} */
|
|
11
7
|
export type HttpInterceptorType = 'local' | 'remote';
|
|
12
8
|
|
|
13
|
-
/**
|
|
14
|
-
* The platform where an HTTP interceptor is running.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
17
|
-
*/
|
|
9
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference} */
|
|
18
10
|
export type HttpInterceptorPlatform = 'node' | 'browser';
|
|
19
11
|
|
|
20
|
-
/**
|
|
21
|
-
* The strategy to treat unhandled requests.
|
|
22
|
-
*
|
|
23
|
-
* When `log` is `true` or `undefined`, warnings about unhandled requests are logged to the console. If provided a
|
|
24
|
-
* factory, unhandled request warnings will be logged if the function returns a
|
|
25
|
-
* {@link UnhandledRequestStrategy.Declaration strategy declaration} containing `log` as `true` or `undefined`.
|
|
26
|
-
*
|
|
27
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
28
|
-
*/
|
|
12
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
29
13
|
export namespace UnhandledRequestStrategy {
|
|
30
|
-
/**
|
|
31
|
-
* The action to take when an unhandled request is intercepted.
|
|
32
|
-
*
|
|
33
|
-
* In a {@link https://github.com/zimicjs/zimic/wiki/getting‐started#local-http-interceptors local interceptor}, the
|
|
34
|
-
* action is always `bypass`, meaning that unhandled requests pass through the interceptor and reach the real network.
|
|
35
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#local-http-interceptors Remote interceptors} always use
|
|
36
|
-
* `reject`, since unhandled requests that react an
|
|
37
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server} cannot be bypassed.
|
|
38
|
-
*
|
|
39
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
40
|
-
*/
|
|
14
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
41
15
|
export type Action = 'bypass' | 'reject';
|
|
42
16
|
|
|
43
|
-
/**
|
|
44
|
-
* A static declaration of the strategy to use for unhandled requests.
|
|
45
|
-
*
|
|
46
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
47
|
-
*/
|
|
17
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
48
18
|
export interface Declaration<DeclarationAction extends Action = Action> {
|
|
49
|
-
/**
|
|
19
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
50
20
|
action: DeclarationAction;
|
|
51
21
|
|
|
52
|
-
/**
|
|
53
|
-
* Whether to log unhandled requests to the console.
|
|
54
|
-
*
|
|
55
|
-
* @default true
|
|
56
|
-
*/
|
|
22
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
57
23
|
log?: boolean;
|
|
58
24
|
}
|
|
59
25
|
|
|
60
|
-
/**
|
|
61
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request.
|
|
62
|
-
*
|
|
63
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
64
|
-
*/
|
|
26
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
65
27
|
export type DeclarationFactory<DeclarationAction extends Action = Action> = (
|
|
66
28
|
request: UnhandledHttpInterceptorRequest,
|
|
67
29
|
) => PossiblePromise<Declaration<DeclarationAction>>;
|
|
68
30
|
|
|
69
|
-
/**
|
|
70
|
-
* A static declaration of the strategy to use for unhandled requests in local interceptors.
|
|
71
|
-
*
|
|
72
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
73
|
-
*/
|
|
31
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
74
32
|
export type LocalDeclaration = Declaration;
|
|
75
33
|
|
|
76
|
-
/**
|
|
77
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request in local interceptors.
|
|
78
|
-
*
|
|
79
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
80
|
-
*/
|
|
34
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
81
35
|
export type LocalDeclarationFactory = DeclarationFactory;
|
|
82
36
|
|
|
83
|
-
/**
|
|
84
|
-
* A static declaration of the strategy to use for unhandled requests in remote interceptors.
|
|
85
|
-
*
|
|
86
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
87
|
-
*/
|
|
37
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
88
38
|
export type RemoteDeclaration = Declaration<'reject'>;
|
|
89
39
|
|
|
90
|
-
/**
|
|
91
|
-
* A factory to create dynamic unhandled request strategies based on the intercepted request in remote interceptors.
|
|
92
|
-
*
|
|
93
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
94
|
-
*/
|
|
40
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
95
41
|
export type RemoteDeclarationFactory = DeclarationFactory<'reject'>;
|
|
96
42
|
|
|
97
|
-
/**
|
|
43
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
98
44
|
export type Local = LocalDeclaration | LocalDeclarationFactory;
|
|
99
45
|
|
|
100
|
-
/**
|
|
46
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
101
47
|
export type Remote = RemoteDeclaration | RemoteDeclarationFactory;
|
|
102
48
|
}
|
|
103
49
|
|
|
104
50
|
export type UnhandledRequestStrategy = UnhandledRequestStrategy.Local | UnhandledRequestStrategy.Remote;
|
|
105
51
|
|
|
106
52
|
export interface SharedHttpInterceptorOptions {
|
|
107
|
-
/**
|
|
108
|
-
* The type of the HTTP interceptor.
|
|
109
|
-
*
|
|
110
|
-
* @default 'local'
|
|
111
|
-
*/
|
|
53
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
112
54
|
type?: HttpInterceptorType;
|
|
113
55
|
|
|
114
|
-
/**
|
|
115
|
-
* Represents the URL that should be matched by the interceptor. Any request starting with this base URL will be
|
|
116
|
-
* intercepted if a matching
|
|
117
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler handler} exists.
|
|
118
|
-
*
|
|
119
|
-
* For {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptors}, this
|
|
120
|
-
* base URL should point to an
|
|
121
|
-
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}. It may include
|
|
122
|
-
* additional paths to differentiate between conflicting mocks.
|
|
123
|
-
*/
|
|
56
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
124
57
|
baseURL: string;
|
|
125
58
|
|
|
126
|
-
/**
|
|
127
|
-
* Configures if the intercepted requests are saved and how they are handled.
|
|
128
|
-
*
|
|
129
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
130
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
131
|
-
*/
|
|
59
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
132
60
|
requestSaving?: Partial<HttpInterceptorRequestSaving>;
|
|
133
61
|
}
|
|
134
62
|
|
|
135
63
|
/**
|
|
136
|
-
*
|
|
137
|
-
* {@link https://
|
|
138
|
-
*
|
|
139
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#creating-a-local-http-interceptor Creating a local HTTP interceptor}
|
|
64
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/local-interceptors#creating-a-local-http-interceptor Creating a local HTTP interceptor}
|
|
65
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference}
|
|
140
66
|
*/
|
|
141
67
|
export interface LocalHttpInterceptorOptions extends SharedHttpInterceptorOptions {
|
|
142
68
|
type?: 'local';
|
|
143
69
|
|
|
144
|
-
/**
|
|
145
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
146
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
147
|
-
* unhandled request.
|
|
148
|
-
*
|
|
149
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
150
|
-
*/
|
|
70
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
151
71
|
onUnhandledRequest?: UnhandledRequestStrategy.Local;
|
|
152
72
|
}
|
|
153
73
|
|
|
74
|
+
interface HttpInterceptorAuthOptions {
|
|
75
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */
|
|
76
|
+
token: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
154
79
|
/**
|
|
155
|
-
*
|
|
156
|
-
* {@link https://
|
|
157
|
-
*
|
|
158
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#creating-a-remote-http-interceptor Creating a remote HTTP interceptor}
|
|
80
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#creating-a-remote-http-interceptor Creating a remote HTTP interceptor}
|
|
81
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference}
|
|
159
82
|
*/
|
|
160
83
|
export interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions {
|
|
161
84
|
type: 'remote';
|
|
162
85
|
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#authentication Interceptor server authentication}
|
|
168
|
-
*/
|
|
169
|
-
auth?: {
|
|
170
|
-
/**
|
|
171
|
-
* The authentication token to use.
|
|
172
|
-
*
|
|
173
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#authentication Interceptor server authentication}
|
|
174
|
-
*/
|
|
175
|
-
token: string;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
180
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
181
|
-
* unhandled request.
|
|
182
|
-
*
|
|
183
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
184
|
-
*/
|
|
86
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication} */
|
|
87
|
+
auth?: HttpInterceptorAuthOptions;
|
|
88
|
+
|
|
89
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
185
90
|
onUnhandledRequest?: UnhandledRequestStrategy.Remote;
|
|
186
91
|
}
|
|
187
92
|
|
|
188
|
-
/**
|
|
189
|
-
* The options to create an
|
|
190
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor HTTP interceptor}.
|
|
191
|
-
*
|
|
192
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `createHttpInterceptor(options)` API reference}
|
|
193
|
-
*/
|
|
93
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor()` API reference} */
|
|
194
94
|
export type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions;
|