@zimic/interceptor 1.2.7-canary.2 → 1.3.0-canary.1
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-6GEP6R3L.mjs → chunk-4L2JH2L4.mjs} +80 -23
- package/dist/chunk-4L2JH2L4.mjs.map +1 -0
- package/dist/{chunk-PB4TJVK3.js → chunk-F5OGZSHS.js} +80 -23
- package/dist/chunk-F5OGZSHS.js.map +1 -0
- package/dist/cli.js +17 -19
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +95 -6
- package/dist/http.js +253 -186
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +254 -187
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +2 -2
- package/src/cli/server/start.ts +7 -2
- package/src/http/interceptor/HttpInterceptorClient.ts +8 -10
- package/src/http/interceptor/types/options.ts +11 -5
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +73 -15
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +36 -11
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +34 -13
- package/src/http/interceptorWorker/types/http.ts +6 -1
- package/src/http/interceptorWorker/types/msw.ts +0 -9
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +2 -4
- package/src/http/requestHandler/errors/TimesCheckError.ts +1 -1
- package/src/http/requestHandler/types/requests.ts +16 -2
- package/src/server/InterceptorServer.ts +13 -5
- package/src/server/constants.ts +1 -1
- package/src/server/errors/UnsupportedResponseBypassError.ts +11 -0
- package/src/utils/crypto.ts +1 -1
- package/src/utils/fetch.ts +25 -6
- package/src/utils/files.ts +1 -1
- package/src/utils/logging.ts +2 -2
- package/src/webSocket/WebSocketClient.ts +1 -1
- package/dist/chunk-6GEP6R3L.mjs.map +0 -1
- package/dist/chunk-PB4TJVK3.js.map +0 -1
package/dist/http.d.ts
CHANGED
|
@@ -64,6 +64,83 @@ declare class DisabledRequestSavingError extends TypeError {
|
|
|
64
64
|
constructor();
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
type JSON = {
|
|
68
|
+
[key: string]: JSON;
|
|
69
|
+
} | JSON[] | string | number | boolean | null | undefined;
|
|
70
|
+
declare namespace JSON {
|
|
71
|
+
type Loose = Record<string, any> | Loose[] | string | number | boolean | null | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Represents or validates a type that is compatible with JSON.
|
|
75
|
+
*
|
|
76
|
+
* **IMPORTANT**: the input of `JSONValue` and all of its internal types must be declared inline or as a type aliases
|
|
77
|
+
* (`type`). They cannot be interfaces.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* import { type JSONValue } from '@zimic/http';
|
|
81
|
+
*
|
|
82
|
+
* // Can be used as a standalone type:
|
|
83
|
+
* const value: JSONValue = {
|
|
84
|
+
* name: 'example',
|
|
85
|
+
* tags: ['one', 'two'],
|
|
86
|
+
* };
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* import { type JSONValue } from '@zimic/http';
|
|
90
|
+
*
|
|
91
|
+
* // Can be used with a type argument to validate a JSON value:
|
|
92
|
+
* type ValidJSON = JSONValue<{
|
|
93
|
+
* id: string;
|
|
94
|
+
* email: string;
|
|
95
|
+
* createdAt: string;
|
|
96
|
+
* }>;
|
|
97
|
+
*
|
|
98
|
+
* // This results in a type error:
|
|
99
|
+
* type InvalidJSON = JSONValue<{
|
|
100
|
+
* id: string;
|
|
101
|
+
* email: string;
|
|
102
|
+
* createdAt: Date; // `Date` is not a valid JSON value.
|
|
103
|
+
* save: () => Promise<void>; // Functions are not valid JSON values.
|
|
104
|
+
* }>;
|
|
105
|
+
*/
|
|
106
|
+
type JSONValue<Type extends JSON = JSON> = Type;
|
|
107
|
+
declare namespace JSONValue {
|
|
108
|
+
/** A loose version of the JSON value type. JSON objects are not strictly typed. */
|
|
109
|
+
type Loose<Type extends JSON.Loose = JSON.Loose> = Type;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Recursively converts a type to its JSON-serialized version. Dates are converted to strings and keys with non-JSON
|
|
113
|
+
* values are excluded.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* import { type JSONSerialized } from '@zimic/http';
|
|
117
|
+
*
|
|
118
|
+
* type SerializedUser = JSONSerialized<{
|
|
119
|
+
* id: string;
|
|
120
|
+
* email: string;
|
|
121
|
+
* createdAt: Date;
|
|
122
|
+
* save: () => Promise<void>;
|
|
123
|
+
* }>;
|
|
124
|
+
* // {
|
|
125
|
+
* // id: string;
|
|
126
|
+
* // email: string;
|
|
127
|
+
* // createdAt: string;
|
|
128
|
+
* // }
|
|
129
|
+
*/
|
|
130
|
+
type JSONSerialized<Type> = Type extends JSONValue ? Type : Type extends Date ? string : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map<infer _Key, infer _Value> ? Record<string, never> : Type extends Set<infer _Value> ? Record<string, never> : Type extends (infer ArrayItem)[] ? JSONSerialized<ArrayItem>[] : Type extends object ? {
|
|
131
|
+
[Key in keyof Type as [JSONSerialized<Type[Key]>] extends [never] ? never : Key]: JSONSerialized<Type[Key]>;
|
|
132
|
+
} : never;
|
|
133
|
+
declare global {
|
|
134
|
+
interface JSON {
|
|
135
|
+
readonly value: unique symbol;
|
|
136
|
+
stringify<Value>(value: Value, replacer?: ((this: any, key: string, value: Value) => any) | (number | string)[] | null, space?: string | number): JSONStringified<Value>;
|
|
137
|
+
parse<Value>(text: JSONStringified<Value>, reviver?: (this: any, key: string, value: any) => any): JSONSerialized<Value>;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
type JSONStringified<Value> = string & {
|
|
141
|
+
[JSON.value]: JSONSerialized<Value>;
|
|
142
|
+
};
|
|
143
|
+
|
|
67
144
|
type Default<Type, IfEmpty = never> = [undefined | void] extends [Type] ? IfEmpty : Exclude<Type, undefined | void>;
|
|
68
145
|
type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
|
|
69
146
|
type PossiblePromise<Type> = Type | PromiseLike<Type>;
|
|
@@ -98,10 +175,18 @@ type HttpRequestHandlerResponseDeclarationWithHeaders<ResponseSchema extends Htt
|
|
|
98
175
|
headers: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema>;
|
|
99
176
|
};
|
|
100
177
|
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
101
|
-
type
|
|
178
|
+
type HttpRequestHandlerStatusResponseDeclaration<MethodSchema extends HttpMethodSchema = HttpMethodSchema, StatusCode extends HttpStatusCode = HttpStatusCode> = StatusCode extends StatusCode ? {
|
|
102
179
|
status: StatusCode;
|
|
180
|
+
action?: never;
|
|
103
181
|
} & HttpRequestHandlerResponseWithBody<Default<Default<MethodSchema['response']>[StatusCode]>, StatusCode> & HttpRequestHandlerResponseDeclarationWithHeaders<Default<Default<MethodSchema['response']>[StatusCode]>> : never;
|
|
104
182
|
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
183
|
+
interface HttpRequestHandlerActionResponseDeclaration {
|
|
184
|
+
status?: never;
|
|
185
|
+
action: UnhandledRequestStrategy.Action;
|
|
186
|
+
}
|
|
187
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
188
|
+
type HttpRequestHandlerResponseDeclaration<MethodSchema extends HttpMethodSchema = HttpMethodSchema, StatusCode extends HttpStatusCode = HttpStatusCode> = HttpRequestHandlerStatusResponseDeclaration<MethodSchema, StatusCode> | HttpRequestHandlerActionResponseDeclaration;
|
|
189
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond `handler.respond()` API reference} */
|
|
105
190
|
type HttpRequestHandlerResponseDeclarationFactory<Path extends string, MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode = HttpStatusCode> = (request: Omit<HttpInterceptorRequest<Path, MethodSchema>, 'response'>) => PossiblePromise<HttpRequestHandlerResponseDeclaration<MethodSchema, StatusCode>>;
|
|
106
191
|
/** @see {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerdelay `handler.delay()` API reference} */
|
|
107
192
|
type HttpRequestHandlerResponseDelayFactory<Path extends string, MethodSchema extends HttpMethodSchema> = (request: Omit<HttpInterceptorRequest<Path, MethodSchema>, 'response'>) => PossiblePromise<number>;
|
|
@@ -177,7 +262,11 @@ type HttpInterceptorPlatform = 'node' | 'browser';
|
|
|
177
262
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
178
263
|
declare namespace UnhandledRequestStrategy {
|
|
179
264
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
180
|
-
type
|
|
265
|
+
type LocalAction = 'bypass' | 'reject';
|
|
266
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
267
|
+
type RemoteAction = 'reject';
|
|
268
|
+
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
269
|
+
type Action = LocalAction | RemoteAction;
|
|
181
270
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
182
271
|
interface Declaration<DeclarationAction extends Action = Action> {
|
|
183
272
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
@@ -188,13 +277,13 @@ declare namespace UnhandledRequestStrategy {
|
|
|
188
277
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
189
278
|
type DeclarationFactory<DeclarationAction extends Action = Action> = (request: UnhandledHttpInterceptorRequest) => PossiblePromise<Declaration<DeclarationAction>>;
|
|
190
279
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
191
|
-
type LocalDeclaration = Declaration
|
|
280
|
+
type LocalDeclaration = Declaration<LocalAction>;
|
|
192
281
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
193
|
-
type LocalDeclarationFactory = DeclarationFactory
|
|
282
|
+
type LocalDeclarationFactory = DeclarationFactory<LocalAction>;
|
|
194
283
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
195
|
-
type RemoteDeclaration = Declaration<
|
|
284
|
+
type RemoteDeclaration = Declaration<RemoteAction>;
|
|
196
285
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
197
|
-
type RemoteDeclarationFactory = DeclarationFactory<
|
|
286
|
+
type RemoteDeclarationFactory = DeclarationFactory<RemoteAction>;
|
|
198
287
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|
|
199
288
|
type Local = LocalDeclaration | LocalDeclarationFactory;
|
|
200
289
|
/** @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests} */
|