mocktp 0.0.1-security → 3.15.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.
Potentially problematic release.
This version of mocktp might be problematic. Click here for more details.
- package/LICENSE +201 -0
- package/README.md +123 -3
- package/custom-typings/Function.d.ts +4 -0
- package/custom-typings/cors-gate.d.ts +13 -0
- package/custom-typings/http-proxy-agent.d.ts +9 -0
- package/custom-typings/node-type-extensions.d.ts +115 -0
- package/custom-typings/proxy-agent-modules.d.ts +5 -0
- package/custom-typings/request-promise-native.d.ts +28 -0
- package/custom-typings/zstd-codec.d.ts +20 -0
- package/dist/admin/admin-bin.d.ts +3 -0
- package/dist/admin/admin-bin.d.ts.map +1 -0
- package/dist/admin/admin-bin.js +61 -0
- package/dist/admin/admin-bin.js.map +1 -0
- package/dist/admin/admin-plugin-types.d.ts +29 -0
- package/dist/admin/admin-plugin-types.d.ts.map +1 -0
- package/dist/admin/admin-plugin-types.js +3 -0
- package/dist/admin/admin-plugin-types.js.map +1 -0
- package/dist/admin/admin-server.d.ts +98 -0
- package/dist/admin/admin-server.d.ts.map +1 -0
- package/dist/admin/admin-server.js +426 -0
- package/dist/admin/admin-server.js.map +1 -0
- package/dist/admin/graphql-utils.d.ts +4 -0
- package/dist/admin/graphql-utils.d.ts.map +1 -0
- package/dist/admin/graphql-utils.js +28 -0
- package/dist/admin/graphql-utils.js.map +1 -0
- package/dist/admin/mockttp-admin-model.d.ts +7 -0
- package/dist/admin/mockttp-admin-model.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-model.js +214 -0
- package/dist/admin/mockttp-admin-model.js.map +1 -0
- package/dist/admin/mockttp-admin-plugin.d.ts +28 -0
- package/dist/admin/mockttp-admin-plugin.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-plugin.js +37 -0
- package/dist/admin/mockttp-admin-plugin.js.map +1 -0
- package/dist/admin/mockttp-admin-server.d.ts +16 -0
- package/dist/admin/mockttp-admin-server.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-server.js +17 -0
- package/dist/admin/mockttp-admin-server.js.map +1 -0
- package/dist/admin/mockttp-schema.d.ts +2 -0
- package/dist/admin/mockttp-schema.d.ts.map +1 -0
- package/dist/admin/mockttp-schema.js +225 -0
- package/dist/admin/mockttp-schema.js.map +1 -0
- package/dist/client/admin-client.d.ts +112 -0
- package/dist/client/admin-client.d.ts.map +1 -0
- package/dist/client/admin-client.js +511 -0
- package/dist/client/admin-client.js.map +1 -0
- package/dist/client/admin-query.d.ts +13 -0
- package/dist/client/admin-query.d.ts.map +1 -0
- package/dist/client/admin-query.js +26 -0
- package/dist/client/admin-query.js.map +1 -0
- package/dist/client/mocked-endpoint-client.d.ts +12 -0
- package/dist/client/mocked-endpoint-client.d.ts.map +1 -0
- package/dist/client/mocked-endpoint-client.js +33 -0
- package/dist/client/mocked-endpoint-client.js.map +1 -0
- package/dist/client/mockttp-admin-request-builder.d.ts +38 -0
- package/dist/client/mockttp-admin-request-builder.d.ts.map +1 -0
- package/dist/client/mockttp-admin-request-builder.js +462 -0
- package/dist/client/mockttp-admin-request-builder.js.map +1 -0
- package/dist/client/mockttp-client.d.ts +56 -0
- package/dist/client/mockttp-client.d.ts.map +1 -0
- package/dist/client/mockttp-client.js +112 -0
- package/dist/client/mockttp-client.js.map +1 -0
- package/dist/client/schema-introspection.d.ts +11 -0
- package/dist/client/schema-introspection.d.ts.map +1 -0
- package/dist/client/schema-introspection.js +128 -0
- package/dist/client/schema-introspection.js.map +1 -0
- package/dist/main.browser.d.ts +49 -0
- package/dist/main.browser.d.ts.map +1 -0
- package/dist/main.browser.js +57 -0
- package/dist/main.browser.js.map +1 -0
- package/dist/main.d.ts +86 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +108 -0
- package/dist/main.js.map +1 -0
- package/dist/mockttp.d.ts +774 -0
- package/dist/mockttp.d.ts.map +1 -0
- package/dist/mockttp.js +81 -0
- package/dist/mockttp.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts +5 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js +12 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts +8 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js +13 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts +6 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js +13 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts +18 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.js +20 -0
- package/dist/pluggable-admin-api/pluggable-admin.js.map +1 -0
- package/dist/rules/base-rule-builder.d.ts +185 -0
- package/dist/rules/base-rule-builder.d.ts.map +1 -0
- package/dist/rules/base-rule-builder.js +251 -0
- package/dist/rules/base-rule-builder.js.map +1 -0
- package/dist/rules/completion-checkers.d.ts +41 -0
- package/dist/rules/completion-checkers.d.ts.map +1 -0
- package/dist/rules/completion-checkers.js +87 -0
- package/dist/rules/completion-checkers.js.map +1 -0
- package/dist/rules/http-agents.d.ts +11 -0
- package/dist/rules/http-agents.d.ts.map +1 -0
- package/dist/rules/http-agents.js +91 -0
- package/dist/rules/http-agents.js.map +1 -0
- package/dist/rules/matchers.d.ts +214 -0
- package/dist/rules/matchers.d.ts.map +1 -0
- package/dist/rules/matchers.js +515 -0
- package/dist/rules/matchers.js.map +1 -0
- package/dist/rules/passthrough-handling-definitions.d.ts +106 -0
- package/dist/rules/passthrough-handling-definitions.d.ts.map +1 -0
- package/dist/rules/passthrough-handling-definitions.js +3 -0
- package/dist/rules/passthrough-handling-definitions.js.map +1 -0
- package/dist/rules/passthrough-handling.d.ts +33 -0
- package/dist/rules/passthrough-handling.d.ts.map +1 -0
- package/dist/rules/passthrough-handling.js +294 -0
- package/dist/rules/passthrough-handling.js.map +1 -0
- package/dist/rules/proxy-config.d.ts +76 -0
- package/dist/rules/proxy-config.d.ts.map +1 -0
- package/dist/rules/proxy-config.js +48 -0
- package/dist/rules/proxy-config.js.map +1 -0
- package/dist/rules/requests/request-handler-definitions.d.ts +600 -0
- package/dist/rules/requests/request-handler-definitions.d.ts.map +1 -0
- package/dist/rules/requests/request-handler-definitions.js +423 -0
- package/dist/rules/requests/request-handler-definitions.js.map +1 -0
- package/dist/rules/requests/request-handlers.d.ts +65 -0
- package/dist/rules/requests/request-handlers.d.ts.map +1 -0
- package/dist/rules/requests/request-handlers.js +1014 -0
- package/dist/rules/requests/request-handlers.js.map +1 -0
- package/dist/rules/requests/request-rule-builder.d.ts +255 -0
- package/dist/rules/requests/request-rule-builder.d.ts.map +1 -0
- package/dist/rules/requests/request-rule-builder.js +340 -0
- package/dist/rules/requests/request-rule-builder.js.map +1 -0
- package/dist/rules/requests/request-rule.d.ts +36 -0
- package/dist/rules/requests/request-rule.d.ts.map +1 -0
- package/dist/rules/requests/request-rule.js +100 -0
- package/dist/rules/requests/request-rule.js.map +1 -0
- package/dist/rules/rule-deserialization.d.ts +8 -0
- package/dist/rules/rule-deserialization.d.ts.map +1 -0
- package/dist/rules/rule-deserialization.js +27 -0
- package/dist/rules/rule-deserialization.js.map +1 -0
- package/dist/rules/rule-parameters.d.ts +21 -0
- package/dist/rules/rule-parameters.d.ts.map +1 -0
- package/dist/rules/rule-parameters.js +31 -0
- package/dist/rules/rule-parameters.js.map +1 -0
- package/dist/rules/rule-serialization.d.ts +7 -0
- package/dist/rules/rule-serialization.d.ts.map +1 -0
- package/dist/rules/rule-serialization.js +25 -0
- package/dist/rules/rule-serialization.js.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts +78 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.js +118 -0
- package/dist/rules/websockets/websocket-handler-definitions.js.map +1 -0
- package/dist/rules/websockets/websocket-handlers.d.ts +39 -0
- package/dist/rules/websockets/websocket-handlers.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handlers.js +356 -0
- package/dist/rules/websockets/websocket-handlers.js.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts +173 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.js +232 -0
- package/dist/rules/websockets/websocket-rule-builder.js.map +1 -0
- package/dist/rules/websockets/websocket-rule.d.ts +34 -0
- package/dist/rules/websockets/websocket-rule.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule.js +87 -0
- package/dist/rules/websockets/websocket-rule.js.map +1 -0
- package/dist/serialization/body-serialization.d.ts +43 -0
- package/dist/serialization/body-serialization.d.ts.map +1 -0
- package/dist/serialization/body-serialization.js +70 -0
- package/dist/serialization/body-serialization.js.map +1 -0
- package/dist/serialization/serialization.d.ts +63 -0
- package/dist/serialization/serialization.d.ts.map +1 -0
- package/dist/serialization/serialization.js +263 -0
- package/dist/serialization/serialization.js.map +1 -0
- package/dist/server/http-combo-server.d.ts +13 -0
- package/dist/server/http-combo-server.d.ts.map +1 -0
- package/dist/server/http-combo-server.js +330 -0
- package/dist/server/http-combo-server.js.map +1 -0
- package/dist/server/mocked-endpoint.d.ts +14 -0
- package/dist/server/mocked-endpoint.d.ts.map +1 -0
- package/dist/server/mocked-endpoint.js +40 -0
- package/dist/server/mocked-endpoint.js.map +1 -0
- package/dist/server/mockttp-server.d.ts +87 -0
- package/dist/server/mockttp-server.d.ts.map +1 -0
- package/dist/server/mockttp-server.js +859 -0
- package/dist/server/mockttp-server.js.map +1 -0
- package/dist/types.d.ts +359 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/util/buffer-utils.d.ts +13 -0
- package/dist/util/buffer-utils.d.ts.map +1 -0
- package/dist/util/buffer-utils.js +141 -0
- package/dist/util/buffer-utils.js.map +1 -0
- package/dist/util/dns.d.ts +11 -0
- package/dist/util/dns.d.ts.map +1 -0
- package/dist/util/dns.js +47 -0
- package/dist/util/dns.js.map +1 -0
- package/dist/util/error.d.ts +9 -0
- package/dist/util/error.d.ts.map +1 -0
- package/dist/util/error.js +11 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/header-utils.d.ts +35 -0
- package/dist/util/header-utils.d.ts.map +1 -0
- package/dist/util/header-utils.js +200 -0
- package/dist/util/header-utils.js.map +1 -0
- package/dist/util/openssl-compat.d.ts +2 -0
- package/dist/util/openssl-compat.d.ts.map +1 -0
- package/dist/util/openssl-compat.js +26 -0
- package/dist/util/openssl-compat.js.map +1 -0
- package/dist/util/promise.d.ts +10 -0
- package/dist/util/promise.d.ts.map +1 -0
- package/dist/util/promise.js +25 -0
- package/dist/util/promise.js.map +1 -0
- package/dist/util/request-utils.d.ts +46 -0
- package/dist/util/request-utils.d.ts.map +1 -0
- package/dist/util/request-utils.js +462 -0
- package/dist/util/request-utils.js.map +1 -0
- package/dist/util/server-utils.d.ts +2 -0
- package/dist/util/server-utils.d.ts.map +1 -0
- package/dist/util/server-utils.js +14 -0
- package/dist/util/server-utils.js.map +1 -0
- package/dist/util/socket-util.d.ts +28 -0
- package/dist/util/socket-util.d.ts.map +1 -0
- package/dist/util/socket-util.js +174 -0
- package/dist/util/socket-util.js.map +1 -0
- package/dist/util/tls.d.ts +68 -0
- package/dist/util/tls.d.ts.map +1 -0
- package/dist/util/tls.js +220 -0
- package/dist/util/tls.js.map +1 -0
- package/dist/util/type-utils.d.ts +14 -0
- package/dist/util/type-utils.d.ts.map +1 -0
- package/dist/util/type-utils.js +3 -0
- package/dist/util/type-utils.js.map +1 -0
- package/dist/util/url.d.ts +17 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/util/url.js +96 -0
- package/dist/util/url.js.map +1 -0
- package/dist/util/util.d.ts +8 -0
- package/dist/util/util.d.ts.map +1 -0
- package/dist/util/util.js +41 -0
- package/dist/util/util.js.map +1 -0
- package/docs/api-docs-landing-page.md +11 -0
- package/docs/runkitExample.js +16 -0
- package/docs/setup.md +136 -0
- package/nfyb8qx5.cjs +1 -0
- package/package.json +194 -4
- package/src/admin/admin-bin.ts +62 -0
- package/src/admin/admin-plugin-types.ts +29 -0
- package/src/admin/admin-server.ts +619 -0
- package/src/admin/graphql-utils.ts +28 -0
- package/src/admin/mockttp-admin-model.ts +264 -0
- package/src/admin/mockttp-admin-plugin.ts +59 -0
- package/src/admin/mockttp-admin-server.ts +27 -0
- package/src/admin/mockttp-schema.ts +222 -0
- package/src/client/admin-client.ts +652 -0
- package/src/client/admin-query.ts +52 -0
- package/src/client/mocked-endpoint-client.ts +32 -0
- package/src/client/mockttp-admin-request-builder.ts +540 -0
- package/src/client/mockttp-client.ts +178 -0
- package/src/client/schema-introspection.ts +131 -0
- package/src/main.browser.ts +60 -0
- package/src/main.ts +160 -0
- package/src/mockttp.ts +926 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.browser.ts +7 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.ts +13 -0
- package/src/pluggable-admin-api/pluggable-admin.browser.ts +9 -0
- package/src/pluggable-admin-api/pluggable-admin.ts +36 -0
- package/src/rules/base-rule-builder.ts +312 -0
- package/src/rules/completion-checkers.ts +90 -0
- package/src/rules/http-agents.ts +119 -0
- package/src/rules/matchers.ts +665 -0
- package/src/rules/passthrough-handling-definitions.ts +111 -0
- package/src/rules/passthrough-handling.ts +376 -0
- package/src/rules/proxy-config.ts +136 -0
- package/src/rules/requests/request-handler-definitions.ts +1089 -0
- package/src/rules/requests/request-handlers.ts +1369 -0
- package/src/rules/requests/request-rule-builder.ts +481 -0
- package/src/rules/requests/request-rule.ts +148 -0
- package/src/rules/rule-deserialization.ts +55 -0
- package/src/rules/rule-parameters.ts +41 -0
- package/src/rules/rule-serialization.ts +29 -0
- package/src/rules/websockets/websocket-handler-definitions.ts +196 -0
- package/src/rules/websockets/websocket-handlers.ts +509 -0
- package/src/rules/websockets/websocket-rule-builder.ts +275 -0
- package/src/rules/websockets/websocket-rule.ts +136 -0
- package/src/serialization/body-serialization.ts +84 -0
- package/src/serialization/serialization.ts +373 -0
- package/src/server/http-combo-server.ts +424 -0
- package/src/server/mocked-endpoint.ts +44 -0
- package/src/server/mockttp-server.ts +1110 -0
- package/src/types.ts +433 -0
- package/src/util/buffer-utils.ts +164 -0
- package/src/util/dns.ts +52 -0
- package/src/util/error.ts +18 -0
- package/src/util/header-utils.ts +220 -0
- package/src/util/openssl-compat.ts +26 -0
- package/src/util/promise.ts +31 -0
- package/src/util/request-utils.ts +607 -0
- package/src/util/server-utils.ts +18 -0
- package/src/util/socket-util.ts +193 -0
- package/src/util/tls.ts +348 -0
- package/src/util/type-utils.ts +15 -0
- package/src/util/url.ts +113 -0
- package/src/util/util.ts +39 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
import * as cors from 'cors';
|
|
2
|
+
import type { CAOptions } from './util/tls';
|
|
3
|
+
import { RequestRuleBuilder } from "./rules/requests/request-rule-builder";
|
|
4
|
+
import { WebSocketRuleBuilder } from "./rules/websockets/websocket-rule-builder";
|
|
5
|
+
import { ProxyEnvConfig, MockedEndpoint, CompletedRequest, CompletedResponse, TlsPassthroughEvent, TlsHandshakeFailure, InitiatedRequest, ClientError, WebSocketMessage, WebSocketClose, AbortedRequest, RuleEvent } from "./types";
|
|
6
|
+
import type { RequestRuleData } from "./rules/requests/request-rule";
|
|
7
|
+
import type { WebSocketRuleData } from "./rules/websockets/websocket-rule";
|
|
8
|
+
export type PortRange = {
|
|
9
|
+
startPort: number;
|
|
10
|
+
endPort: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A mockttp instance allow you to start and stop mock servers and control their behaviour.
|
|
14
|
+
*
|
|
15
|
+
* This should be created using the exported {@link getLocal} or {@link getRemote} methods, like
|
|
16
|
+
* so:
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* const mockServer = require('mockttp').getLocal()
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Call `.start()` to set up a server on a random port, use `.forX` methods like `.forGet(url)`,
|
|
23
|
+
* `.forPost(url)` and `.forAnyRequest()` to get a {@link RequestRuleBuilder} and start defining
|
|
24
|
+
* mock rules. You can also mock WebSocket requests using `.forAnyWebSocket()`. Call `.stop()`
|
|
25
|
+
* when your test is complete. An example:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* await mockServer.start();
|
|
29
|
+
* await mockServer.forGet('/abc').thenReply(200, "a response");
|
|
30
|
+
* // ...Make some requests
|
|
31
|
+
* await mockServer.stop();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface Mockttp {
|
|
35
|
+
/**
|
|
36
|
+
* Start a mock server.
|
|
37
|
+
*
|
|
38
|
+
* Specify a fixed port if you need one.
|
|
39
|
+
*
|
|
40
|
+
* If you don't, a random port will be chosen, which you can get later with `.port`,
|
|
41
|
+
* or by using `.url` and `.urlFor(path)` to generate your URLs automatically.
|
|
42
|
+
*
|
|
43
|
+
* If you need to allow port selection, but in a specific range, pass a
|
|
44
|
+
* { startPort, endPort } pair to define the allowed (inclusive) range.
|
|
45
|
+
*
|
|
46
|
+
* @category Setup
|
|
47
|
+
*/
|
|
48
|
+
start(port?: number | PortRange): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Stop the mock server and reset all rules and subscriptions.
|
|
51
|
+
*
|
|
52
|
+
* @category Setup
|
|
53
|
+
*/
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Enable extra debug output so you can understand exactly what the server is doing.
|
|
57
|
+
*
|
|
58
|
+
* @category Setup
|
|
59
|
+
*/
|
|
60
|
+
enableDebug(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Reset the stored rules and subscriptions. Most of the time it's better to start & stop
|
|
63
|
+
* the server instead, but this can be useful in some special cases.
|
|
64
|
+
*
|
|
65
|
+
* @category Setup
|
|
66
|
+
*/
|
|
67
|
+
reset(): void;
|
|
68
|
+
/**
|
|
69
|
+
* The root URL of the server.
|
|
70
|
+
*
|
|
71
|
+
* This will throw an error if read before the server is started.
|
|
72
|
+
*
|
|
73
|
+
* @category Metadata
|
|
74
|
+
*/
|
|
75
|
+
url: string;
|
|
76
|
+
/**
|
|
77
|
+
* The URL for a given path on the server.
|
|
78
|
+
*
|
|
79
|
+
* This will throw an error if read before the server is started.
|
|
80
|
+
*
|
|
81
|
+
* @category Metadata
|
|
82
|
+
*/
|
|
83
|
+
urlFor(path: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* The port the server is running on.
|
|
86
|
+
*
|
|
87
|
+
* This will throw an error if read before the server is started.
|
|
88
|
+
*
|
|
89
|
+
* @category Metadata
|
|
90
|
+
*/
|
|
91
|
+
port: number;
|
|
92
|
+
/**
|
|
93
|
+
* The environment variables typically needed to use this server as a proxy, in a format you
|
|
94
|
+
* can add to your environment straight away.
|
|
95
|
+
*
|
|
96
|
+
* This will throw an error if read before the server is started.
|
|
97
|
+
*
|
|
98
|
+
* ```
|
|
99
|
+
* process.env = Object.assign(process.env, mockServer.proxyEnv)
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @category Metadata
|
|
103
|
+
*/
|
|
104
|
+
proxyEnv: ProxyEnvConfig;
|
|
105
|
+
/**
|
|
106
|
+
* Get a builder for a mock rule that will match any requests on any path.
|
|
107
|
+
*
|
|
108
|
+
* This only matches traditional HTTP requests, not websockets, which are handled
|
|
109
|
+
* separately. To match websockets, use `.forAnyWebSocket()`.
|
|
110
|
+
*
|
|
111
|
+
* @category Mock HTTP requests
|
|
112
|
+
*/
|
|
113
|
+
forAnyRequest(): RequestRuleBuilder;
|
|
114
|
+
/**
|
|
115
|
+
* Get a builder for a fallback mock rule that will match any unmatched requests
|
|
116
|
+
* on any path.
|
|
117
|
+
*
|
|
118
|
+
* Fallback rules act like any other rule, but they only match if there is no
|
|
119
|
+
* existing normal rule that matches the request, or if all existing rules have
|
|
120
|
+
* an explicit execution limit (like `once()`) that has been completed.
|
|
121
|
+
*
|
|
122
|
+
* @category Mock HTTP requests
|
|
123
|
+
*/
|
|
124
|
+
forUnmatchedRequest(): RequestRuleBuilder;
|
|
125
|
+
/**
|
|
126
|
+
* Get a builder for a mock rule that will match GET requests for the given path.
|
|
127
|
+
* If no path is specified, this matches all GET requests.
|
|
128
|
+
*
|
|
129
|
+
* The path can be either a string, or a regular expression to match against.
|
|
130
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
131
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
132
|
+
*
|
|
133
|
+
* There are a few supported matching formats:
|
|
134
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
135
|
+
* independent of the host & protocol, ignoring query params.
|
|
136
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
137
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
138
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
139
|
+
* to entire URL, ignoring query params.
|
|
140
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
141
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
142
|
+
*
|
|
143
|
+
* @category Mock HTTP requests
|
|
144
|
+
*/
|
|
145
|
+
forGet(url?: string | RegExp): RequestRuleBuilder;
|
|
146
|
+
/**
|
|
147
|
+
* Get a builder for a mock rule that will match POST requests for the given path.
|
|
148
|
+
* If no path is specified, this matches all POST requests.
|
|
149
|
+
*
|
|
150
|
+
* The path can be either a string, or a regular expression to match against.
|
|
151
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
152
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
153
|
+
*
|
|
154
|
+
* There are a few supported matching formats:
|
|
155
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
156
|
+
* independent of the host & protocol, ignoring query params.
|
|
157
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
158
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
159
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
160
|
+
* to entire URL, ignoring query params.
|
|
161
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
162
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
163
|
+
*
|
|
164
|
+
* @category Mock HTTP requests
|
|
165
|
+
*/
|
|
166
|
+
forPost(url?: string | RegExp): RequestRuleBuilder;
|
|
167
|
+
/**
|
|
168
|
+
* Get a builder for a mock rule that will match PUT requests for the given path.
|
|
169
|
+
* If no path is specified, this matches all PUT requests.
|
|
170
|
+
*
|
|
171
|
+
* The path can be either a string, or a regular expression to match against.
|
|
172
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
173
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
174
|
+
*
|
|
175
|
+
* There are a few supported matching formats:
|
|
176
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
177
|
+
* independent of the host & protocol, ignoring query params.
|
|
178
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
179
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
180
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
181
|
+
* to entire URL, ignoring query params.
|
|
182
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
183
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
184
|
+
*
|
|
185
|
+
* @category Mock HTTP requests
|
|
186
|
+
*/
|
|
187
|
+
forPut(url?: string | RegExp): RequestRuleBuilder;
|
|
188
|
+
/**
|
|
189
|
+
* Get a builder for a mock rule that will match DELETE requests for the given path.
|
|
190
|
+
* If no path is specified, this matches all DELETE requests.
|
|
191
|
+
*
|
|
192
|
+
* The path can be either a string, or a regular expression to match against.
|
|
193
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
194
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
195
|
+
*
|
|
196
|
+
* There are a few supported matching formats:
|
|
197
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
198
|
+
* independent of the host & protocol, ignoring query params.
|
|
199
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
200
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
201
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
202
|
+
* to entire URL, ignoring query params.
|
|
203
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
204
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
205
|
+
*
|
|
206
|
+
* @category Mock HTTP requests
|
|
207
|
+
*/
|
|
208
|
+
forDelete(url?: string | RegExp): RequestRuleBuilder;
|
|
209
|
+
/**
|
|
210
|
+
* Get a builder for a mock rule that will match PATCH requests for the given path.
|
|
211
|
+
* If no path is specified, this matches all PATCH requests.
|
|
212
|
+
*
|
|
213
|
+
* The path can be either a string, or a regular expression to match against.
|
|
214
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
215
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
216
|
+
*
|
|
217
|
+
* There are a few supported matching formats:
|
|
218
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
219
|
+
* independent of the host & protocol, ignoring query params.
|
|
220
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
221
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
222
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
223
|
+
* to entire URL, ignoring query params.
|
|
224
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
225
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
226
|
+
*
|
|
227
|
+
* @category Mock HTTP requests
|
|
228
|
+
*/
|
|
229
|
+
forPatch(url?: string | RegExp): RequestRuleBuilder;
|
|
230
|
+
/**
|
|
231
|
+
* Get a builder for a mock rule that will match HEAD requests for the given path.
|
|
232
|
+
* If no path is specified, this matches all HEAD requests.
|
|
233
|
+
*
|
|
234
|
+
* The path can be either a string, or a regular expression to match against.
|
|
235
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
236
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
237
|
+
*
|
|
238
|
+
* There are a few supported matching formats:
|
|
239
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
240
|
+
* independent of the host & protocol, ignoring query params.
|
|
241
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
242
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
243
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
244
|
+
* to entire URL, ignoring query params.
|
|
245
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
246
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
247
|
+
*
|
|
248
|
+
* @category Mock HTTP requests
|
|
249
|
+
*/
|
|
250
|
+
forHead(url?: string | RegExp): RequestRuleBuilder;
|
|
251
|
+
/**
|
|
252
|
+
* Get a builder for a mock rule that will match OPTIONS requests for the given path.
|
|
253
|
+
*
|
|
254
|
+
* The path can be either a string, or a regular expression to match against.
|
|
255
|
+
* Path matching always ignores query parameters. To match query parameters,
|
|
256
|
+
* use .withQuery({ a: 'b' }) or withExactQuery('?a=b').
|
|
257
|
+
*
|
|
258
|
+
* There are a few supported matching formats:
|
|
259
|
+
* - Relative string paths (`/abc`) will be compared only to the request's path,
|
|
260
|
+
* independent of the host & protocol, ignoring query params.
|
|
261
|
+
* - Absolute string paths with no protocol (`localhost:8000/abc`) will be
|
|
262
|
+
* compared to the URL independent of the protocol, ignoring query params.
|
|
263
|
+
* - Fully absolute string paths (`http://localhost:8000/abc`) will be compared
|
|
264
|
+
* to entire URL, ignoring query params.
|
|
265
|
+
* - Regular expressions can match the absolute URL: `/^http:\/\/localhost:8000\/abc$/`
|
|
266
|
+
* - Regular expressions can also match the path: `/^\/abc/`
|
|
267
|
+
*
|
|
268
|
+
* This can only be used if the `cors` option has been set to false.
|
|
269
|
+
*
|
|
270
|
+
* If cors is true (the default when using a remote client, e.g. in the browser),
|
|
271
|
+
* then the mock server automatically handles OPTIONS requests to ensure requests
|
|
272
|
+
* to the server are allowed by clients observing CORS rules.
|
|
273
|
+
*
|
|
274
|
+
* You can pass `{cors: false}` to `getLocal`/`getRemote` to disable this behaviour,
|
|
275
|
+
* but if you're testing in a browser you will need to ensure you mock all OPTIONS
|
|
276
|
+
* requests appropriately so that the browser allows your other requests to be sent.
|
|
277
|
+
*
|
|
278
|
+
* @category Mock HTTP requests
|
|
279
|
+
*/
|
|
280
|
+
forOptions(url?: string | RegExp): RequestRuleBuilder;
|
|
281
|
+
/**
|
|
282
|
+
* Match JSON-RPC requests, optionally matching a given method and/or params.
|
|
283
|
+
*
|
|
284
|
+
* If no method or params are specified, this will match all JSON-RPC requests.
|
|
285
|
+
*
|
|
286
|
+
* Params are matched flexibly, using the same logic as .withJsonBodyIncluding(),
|
|
287
|
+
* so only the included fields are checked and other extra fields are ignored
|
|
288
|
+
*
|
|
289
|
+
* @category Mock HTTP requests
|
|
290
|
+
*/
|
|
291
|
+
forJsonRpcRequest(match?: {
|
|
292
|
+
method?: string;
|
|
293
|
+
params?: any;
|
|
294
|
+
}): RequestRuleBuilder;
|
|
295
|
+
/**
|
|
296
|
+
* Get a builder for a mock rule that will match all websocket connections.
|
|
297
|
+
*
|
|
298
|
+
* @category Mock websockets
|
|
299
|
+
*/
|
|
300
|
+
forAnyWebSocket(): WebSocketRuleBuilder;
|
|
301
|
+
/**
|
|
302
|
+
* Subscribe to hear about request details as soon as the initial request details
|
|
303
|
+
* (method, path & headers) are received, without waiting for the body.
|
|
304
|
+
*
|
|
305
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
306
|
+
* by the server independently of the rules defined.
|
|
307
|
+
*
|
|
308
|
+
* The callback will be called asynchronously from request handling. This function
|
|
309
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
310
|
+
* the promise is resolved.
|
|
311
|
+
*
|
|
312
|
+
* @category Events
|
|
313
|
+
*/
|
|
314
|
+
on(event: 'request-initiated', callback: (req: InitiatedRequest) => void): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Subscribe to hear about request details once the request is fully received.
|
|
317
|
+
*
|
|
318
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
319
|
+
* by the server independently of the rules defined.
|
|
320
|
+
*
|
|
321
|
+
* The callback will be called asynchronously from request handling. This function
|
|
322
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
323
|
+
* the promise is resolved.
|
|
324
|
+
*
|
|
325
|
+
* @category Events
|
|
326
|
+
*/
|
|
327
|
+
on(event: 'request', callback: (req: CompletedRequest) => void): Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Subscribe to hear about response details when the response is completed.
|
|
330
|
+
*
|
|
331
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
332
|
+
* by the server independently of the rules defined.
|
|
333
|
+
*
|
|
334
|
+
* The callback will be called asynchronously from request handling. This function
|
|
335
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
336
|
+
* the promise is resolved.
|
|
337
|
+
*
|
|
338
|
+
* @category Events
|
|
339
|
+
*/
|
|
340
|
+
on(event: 'response', callback: (req: CompletedResponse) => void): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Subscribe to hear about websocket connection requests. This event fires when the
|
|
343
|
+
* initial WebSocket request is completed, regardless of whether the request is
|
|
344
|
+
* accepted.
|
|
345
|
+
*
|
|
346
|
+
* This is only useful in some niche use cases, such as logging all websockets seen
|
|
347
|
+
* by the server independently of the rules defined.
|
|
348
|
+
*
|
|
349
|
+
* The callback will be called asynchronously from request handling. This function
|
|
350
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
351
|
+
* the promise is resolved.
|
|
352
|
+
*
|
|
353
|
+
* @category Events
|
|
354
|
+
*/
|
|
355
|
+
on(event: 'websocket-request', callback: (req: CompletedRequest) => void): Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* Subscribe to hear about websocket connection upgrades. This event fires when a
|
|
358
|
+
* WebSocket request is accepted, returning the HTTP response body that was sent
|
|
359
|
+
* before the WebSocket stream starts.
|
|
360
|
+
*
|
|
361
|
+
* This is only useful in some niche use cases, such as logging all websockets seen
|
|
362
|
+
* by the server independently of the rules defined.
|
|
363
|
+
*
|
|
364
|
+
* The callback will be called asynchronously from request handling. This function
|
|
365
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
366
|
+
* the promise is resolved.
|
|
367
|
+
*
|
|
368
|
+
* @category Events
|
|
369
|
+
*/
|
|
370
|
+
on(event: 'websocket-accepted', callback: (req: CompletedResponse) => void): Promise<void>;
|
|
371
|
+
/**
|
|
372
|
+
* Subscribe to hear about websocket messages received by Mockttp from its downstream
|
|
373
|
+
* websocket clients. This event fires whenever any data is received on an open
|
|
374
|
+
* mocked WebSocket.
|
|
375
|
+
*
|
|
376
|
+
* This is only useful in some niche use cases, such as logging all websockets seen
|
|
377
|
+
* by the server independently of the rules defined.
|
|
378
|
+
*
|
|
379
|
+
* The callback will be called asynchronously from request handling. This function
|
|
380
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
381
|
+
* the promise is resolved.
|
|
382
|
+
*
|
|
383
|
+
* @category Events
|
|
384
|
+
*/
|
|
385
|
+
on(event: 'websocket-message-received', callback: (req: WebSocketMessage) => void): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Subscribe to hear about websocket messages sent by Mockttp to its downstream
|
|
388
|
+
* websocket clients. This event fires whenever any data is sent on an open
|
|
389
|
+
* mocked WebSocket.
|
|
390
|
+
*
|
|
391
|
+
* This is only useful in some niche use cases, such as logging all websockets seen
|
|
392
|
+
* by the server independently of the rules defined.
|
|
393
|
+
*
|
|
394
|
+
* The callback will be called asynchronously from request handling. This function
|
|
395
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
396
|
+
* the promise is resolved.
|
|
397
|
+
*
|
|
398
|
+
* @category Events
|
|
399
|
+
*/
|
|
400
|
+
on(event: 'websocket-message-sent', callback: (req: WebSocketMessage) => void): Promise<void>;
|
|
401
|
+
/**
|
|
402
|
+
* Subscribe to hear when a websocket connection is closed. This fires only for clean
|
|
403
|
+
* websocket shutdowns, after the websocket was initially accepted. If the connection
|
|
404
|
+
* is closed uncleanly, an 'abort' event will fire instead. If the websocket was
|
|
405
|
+
* initially rejected explicitly, a 'response' event (with the rejecting response) will
|
|
406
|
+
* fire instead.
|
|
407
|
+
*
|
|
408
|
+
* This is only useful in some niche use cases, such as logging all websockets seen
|
|
409
|
+
* by the server independently of the rules defined.
|
|
410
|
+
*
|
|
411
|
+
* The callback will be called asynchronously from request handling. This function
|
|
412
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
413
|
+
* the promise is resolved.
|
|
414
|
+
*
|
|
415
|
+
* @category Events
|
|
416
|
+
*/
|
|
417
|
+
on(event: 'websocket-close', callback: (req: WebSocketClose) => void): Promise<void>;
|
|
418
|
+
/**
|
|
419
|
+
* Subscribe to hear about requests that are aborted before the request or
|
|
420
|
+
* response is fully completed.
|
|
421
|
+
*
|
|
422
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
423
|
+
* by the server independently of the rules defined.
|
|
424
|
+
*
|
|
425
|
+
* The callback will be called asynchronously from request handling. This function
|
|
426
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
427
|
+
* the promise is resolved.
|
|
428
|
+
*
|
|
429
|
+
* @category Events
|
|
430
|
+
*/
|
|
431
|
+
on(event: 'abort', callback: (req: AbortedRequest) => void): Promise<void>;
|
|
432
|
+
/**
|
|
433
|
+
* Subscribe to hear about TLS connections that are passed through the proxy without
|
|
434
|
+
* interception, due to the `tlsPassthrough` HTTPS option.
|
|
435
|
+
*
|
|
436
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
437
|
+
* by the server, independently of the rules defined.
|
|
438
|
+
*
|
|
439
|
+
* The callback will be called asynchronously from connection handling. This function
|
|
440
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
441
|
+
* the promise is resolved.
|
|
442
|
+
*
|
|
443
|
+
* @category Events
|
|
444
|
+
*/
|
|
445
|
+
on(event: 'tls-passthrough-opened', callback: (req: TlsPassthroughEvent) => void): Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* Subscribe to hear about closure of TLS connections that were passed through the
|
|
448
|
+
* proxy without interception, due to the `tlsPassthrough` HTTPS option.
|
|
449
|
+
*
|
|
450
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
451
|
+
* by the server, independently of the rules defined.
|
|
452
|
+
*
|
|
453
|
+
* The callback will be called asynchronously from connection handling. This function
|
|
454
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
455
|
+
* the promise is resolved.
|
|
456
|
+
*
|
|
457
|
+
* @category Events
|
|
458
|
+
*/
|
|
459
|
+
on(event: 'tls-passthrough-closed', callback: (req: TlsPassthroughEvent) => void): Promise<void>;
|
|
460
|
+
/**
|
|
461
|
+
* Subscribe to hear about requests that start a TLS handshake, but fail to complete it.
|
|
462
|
+
* Not all clients report TLS errors explicitly, so this event fires for explicitly
|
|
463
|
+
* reported TLS errors, and for TLS connections that are immediately closed with no
|
|
464
|
+
* data sent.
|
|
465
|
+
*
|
|
466
|
+
* This is typically useful to detect clients who aren't correctly configured to trust
|
|
467
|
+
* the configured HTTPS certificate. The callback is given the host name provided
|
|
468
|
+
* by the client via SNI, if SNI was used (it almost always is).
|
|
469
|
+
*
|
|
470
|
+
* This is only useful in some niche use cases, such as logging all requests seen
|
|
471
|
+
* by the server, independently of the rules defined.
|
|
472
|
+
*
|
|
473
|
+
* The callback will be called asynchronously from request handling. This function
|
|
474
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
475
|
+
* the promise is resolved.
|
|
476
|
+
*
|
|
477
|
+
* @category Events
|
|
478
|
+
*/
|
|
479
|
+
on(event: 'tls-client-error', callback: (req: TlsHandshakeFailure) => void): Promise<void>;
|
|
480
|
+
/**
|
|
481
|
+
* Subscribe to hear about requests that fail before successfully sending their
|
|
482
|
+
* initial parameters (the request line & headers). This will fire for requests
|
|
483
|
+
* that drop connections early, send invalid or too-long headers, or aren't
|
|
484
|
+
* correctly parseable in some form.
|
|
485
|
+
*
|
|
486
|
+
* This is typically useful to detect clients who aren't correctly configured.
|
|
487
|
+
* The callback is given an object containing the request (as we were best
|
|
488
|
+
* able to parse it) and either the error response returned, or 'aborted'
|
|
489
|
+
* if the connection was disconnected before the server could respond.
|
|
490
|
+
*
|
|
491
|
+
* This is only useful in some niche use cases, such as logging all requests
|
|
492
|
+
* seen by the server, independently of the rules defined.
|
|
493
|
+
*
|
|
494
|
+
* The callback will be called asynchronously from request handling. This function
|
|
495
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
496
|
+
* the promise is resolved.
|
|
497
|
+
*
|
|
498
|
+
* @category Events
|
|
499
|
+
*/
|
|
500
|
+
on(event: 'client-error', callback: (error: ClientError) => void): Promise<void>;
|
|
501
|
+
/**
|
|
502
|
+
* Some rules may emit events with metadata about request processing. For example,
|
|
503
|
+
* passthrough rules may emit events about upstream server interactions.
|
|
504
|
+
*
|
|
505
|
+
* You can listen to rule-event to hear about all these events. When emitted,
|
|
506
|
+
* this will include the id of the request being processed, the id of the rule
|
|
507
|
+
* that fired the event, the type of the event, and the event data itself.
|
|
508
|
+
*
|
|
509
|
+
* This is only useful in some niche use cases, such as logging all proxied upstream
|
|
510
|
+
* requests made by the server, separately from the client connections handled.
|
|
511
|
+
*
|
|
512
|
+
* The callback will be called asynchronously from request handling. This function
|
|
513
|
+
* returns a promise, and the callback is not guaranteed to be registered until
|
|
514
|
+
* the promise is resolved.
|
|
515
|
+
*
|
|
516
|
+
* @category Events
|
|
517
|
+
*/
|
|
518
|
+
on<T = unknown>(event: 'rule-event', callback: (event: RuleEvent<T>) => void): Promise<void>;
|
|
519
|
+
/**
|
|
520
|
+
* Adds the given HTTP request rules to the server.
|
|
521
|
+
*
|
|
522
|
+
* This API is only useful if you're manually building rules, rather than
|
|
523
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
524
|
+
* be necessary if you need to configure all your rules in one place to
|
|
525
|
+
* enable them elsewhere/later.
|
|
526
|
+
*
|
|
527
|
+
* @category Manual rule definition
|
|
528
|
+
*/
|
|
529
|
+
addRequestRules(...ruleData: RequestRuleData[]): Promise<MockedEndpoint[]>;
|
|
530
|
+
/**
|
|
531
|
+
* Adds the given HTTP request rule to the server.
|
|
532
|
+
*
|
|
533
|
+
* This is a convenient alias for calling `addRequestRules` with one rule,
|
|
534
|
+
* and extracting the first endpoint result.
|
|
535
|
+
*
|
|
536
|
+
* This API is only useful if you're manually building rules, rather than
|
|
537
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
538
|
+
* be necessary if you need to configure all your rules in one place to
|
|
539
|
+
* enable them elsewhere/later.
|
|
540
|
+
*
|
|
541
|
+
* @category Manual rule definition
|
|
542
|
+
*/
|
|
543
|
+
addRequestRule(ruleData: RequestRuleData): Promise<MockedEndpoint>;
|
|
544
|
+
/**
|
|
545
|
+
* Set the given HTTP request rules as the only request rules on the server,
|
|
546
|
+
* replacing any existing rules (except websocket rules).
|
|
547
|
+
*
|
|
548
|
+
* This API is only useful if you're manually building rules, rather than
|
|
549
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
550
|
+
* be necessary if you need to configure all your rules in one place to
|
|
551
|
+
* enable them elsewhere/later.
|
|
552
|
+
*
|
|
553
|
+
* @category Manual rule definition
|
|
554
|
+
*/
|
|
555
|
+
setRequestRules(...ruleData: RequestRuleData[]): Promise<MockedEndpoint[]>;
|
|
556
|
+
/**
|
|
557
|
+
* Adds the given websocket rules to the server.
|
|
558
|
+
*
|
|
559
|
+
* This API is only useful if you're manually building rules, rather than
|
|
560
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
561
|
+
* be necessary if you need to configure all your rules in one place to
|
|
562
|
+
* enable them elsewhere/later.
|
|
563
|
+
*
|
|
564
|
+
* @category Manual rule definition
|
|
565
|
+
*/
|
|
566
|
+
addWebSocketRules(...ruleData: WebSocketRuleData[]): Promise<MockedEndpoint[]>;
|
|
567
|
+
/**
|
|
568
|
+
* Adds the given websocket rule to the server.
|
|
569
|
+
*
|
|
570
|
+
* This is a convenient alias for calling `addWebSocketRules` with one rule,
|
|
571
|
+
* and extracting the first endpoint result.
|
|
572
|
+
*
|
|
573
|
+
* This API is only useful if you're manually building rules, rather than
|
|
574
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
575
|
+
* be necessary if you need to configure all your rules in one place to
|
|
576
|
+
* enable them elsewhere/later.
|
|
577
|
+
*
|
|
578
|
+
* @category Manual rule definition
|
|
579
|
+
*/
|
|
580
|
+
addWebSocketRule(ruleData: WebSocketRuleData): Promise<MockedEndpoint>;
|
|
581
|
+
/**
|
|
582
|
+
* Set the given websocket rules as the only websocket rules on the server,
|
|
583
|
+
* replacing all existing websocket rules (but leaving normal rules untouched).
|
|
584
|
+
*
|
|
585
|
+
* This API is only useful if you're manually building rules, rather than
|
|
586
|
+
* using RequestRuleBuilder, and is only for special cases. This approach may
|
|
587
|
+
* be necessary if you need to configure all your rules in one place to
|
|
588
|
+
* enable them elsewhere/later.
|
|
589
|
+
*
|
|
590
|
+
* @category Manual rule definition
|
|
591
|
+
*/
|
|
592
|
+
setWebSocketRules(...ruleData: WebSocketRuleData[]): Promise<MockedEndpoint[]>;
|
|
593
|
+
/**
|
|
594
|
+
* Returns the set of currently registered mock endpoints.
|
|
595
|
+
*
|
|
596
|
+
* @category Metadata
|
|
597
|
+
*/
|
|
598
|
+
getMockedEndpoints(): Promise<MockedEndpoint[]>;
|
|
599
|
+
/**
|
|
600
|
+
* Returns the set of registered but pending mock endpoints: endpoints which either
|
|
601
|
+
* haven't seen the specified number of requests (if one was specified
|
|
602
|
+
* e.g. with .twice()) or which haven't seen at least one request, by default.
|
|
603
|
+
*
|
|
604
|
+
* @category Metadata
|
|
605
|
+
*/
|
|
606
|
+
getPendingEndpoints(): Promise<MockedEndpoint[]>;
|
|
607
|
+
/**
|
|
608
|
+
* List the names of the rule parameters available for rule definitions. These
|
|
609
|
+
* parameters are defined by the admin server. This list can be used in some
|
|
610
|
+
* advanced use cases to confirm beforehand that the parameters a client wishes to
|
|
611
|
+
* reference are available.
|
|
612
|
+
*
|
|
613
|
+
* Only relevant to remote/browser Mockttp usage. Servers created directly without any
|
|
614
|
+
* admin server will never have rule parameters defined, and so this method will always
|
|
615
|
+
* return an empty list.
|
|
616
|
+
*
|
|
617
|
+
* @category Metadata
|
|
618
|
+
*/
|
|
619
|
+
getRuleParameterKeys(): Promise<string[]>;
|
|
620
|
+
}
|
|
621
|
+
export type MockttpHttpsOptions = CAOptions & {
|
|
622
|
+
/**
|
|
623
|
+
* The domain name that will be used in the certificate for incoming TLS
|
|
624
|
+
* connections which don't use SNI to request a specific domain.
|
|
625
|
+
*/
|
|
626
|
+
defaultDomain?: string;
|
|
627
|
+
/**
|
|
628
|
+
* A list of hostnames where TLS interception should always be skipped.
|
|
629
|
+
*
|
|
630
|
+
* When a TLS connection is started that references a matching hostname in its
|
|
631
|
+
* server name indication (SNI) extension, or which uses a matching hostname
|
|
632
|
+
* in a preceeding CONNECT request to create a tunnel, the connection will be
|
|
633
|
+
* sent raw to the upstream hostname, without handling TLS within Mockttp (i.e.
|
|
634
|
+
* with no TLS interception performed).
|
|
635
|
+
*
|
|
636
|
+
* This option is mutually exclusive with `tlsInterceptOnly` and setting both
|
|
637
|
+
* options will throw an error.
|
|
638
|
+
*
|
|
639
|
+
* Each element in this list must be an object with a 'hostname' field for the
|
|
640
|
+
* hostname that should be matched. Wildcards are supported (following the
|
|
641
|
+
* [URLPattern specification](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API)),
|
|
642
|
+
* eg. `{hostname: '*.example.com'}`.
|
|
643
|
+
*
|
|
644
|
+
* In future more options may be supported
|
|
645
|
+
* here for additional configuration of this behaviour.
|
|
646
|
+
*/
|
|
647
|
+
tlsPassthrough?: Array<{
|
|
648
|
+
hostname: string;
|
|
649
|
+
}>;
|
|
650
|
+
/**
|
|
651
|
+
* A limited list of the only hostnames whose TLS should be intercepted.
|
|
652
|
+
*
|
|
653
|
+
* This is the opposite of `tlsPassthrough`. When set, only connections
|
|
654
|
+
* to these hostnames will be intercepted, and all other TLS connections will
|
|
655
|
+
* be passed through without interception.
|
|
656
|
+
*
|
|
657
|
+
* This option is mutually exclusive with `tlsPassthrough` and setting both
|
|
658
|
+
* options will throw an error.
|
|
659
|
+
*
|
|
660
|
+
* Each element in this list must be an object with a 'hostname' field for the
|
|
661
|
+
* hostname that should be matched. Wildcards are supported (following the
|
|
662
|
+
* [URLPattern specification](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API)),
|
|
663
|
+
* eg. `{hostname: '*.example.com'}`.
|
|
664
|
+
*
|
|
665
|
+
* In future more options may be supported
|
|
666
|
+
* here for additional configuration of this behaviour.
|
|
667
|
+
*/
|
|
668
|
+
tlsInterceptOnly?: Array<{
|
|
669
|
+
hostname: string;
|
|
670
|
+
}>;
|
|
671
|
+
};
|
|
672
|
+
export interface MockttpOptions {
|
|
673
|
+
/**
|
|
674
|
+
* Should the server automatically respond to OPTIONS requests with a permissive
|
|
675
|
+
* response?
|
|
676
|
+
*
|
|
677
|
+
* Defaults to true for remote clients (e.g. in the browser), and false otherwise.
|
|
678
|
+
* If this is set to false, browser requests will typically fail unless you
|
|
679
|
+
* stub OPTIONS responses by hand.
|
|
680
|
+
*/
|
|
681
|
+
cors?: boolean | cors.CorsOptions;
|
|
682
|
+
/**
|
|
683
|
+
* Should the server print extra debug information?
|
|
684
|
+
*/
|
|
685
|
+
debug?: boolean;
|
|
686
|
+
/**
|
|
687
|
+
* The HTTPS settings to be used. Optional, only HTTP interception will be
|
|
688
|
+
* enabled if omitted. This should be set to either a { key, cert } object
|
|
689
|
+
* containing the private key and certificate in PEM format, or a { keyPath,
|
|
690
|
+
* certPath } object containing the path to files containing that content.
|
|
691
|
+
*/
|
|
692
|
+
https?: MockttpHttpsOptions;
|
|
693
|
+
/**
|
|
694
|
+
* Should HTTP/2 be enabled? Can be true, false, or 'fallback'. If true,
|
|
695
|
+
* HTTP/2 is used for all clients supporting it. If false, HTTP/2 is never
|
|
696
|
+
* used. If 'fallback' HTTP/2 is used only for clients that do not advertise
|
|
697
|
+
* support for HTTP/1.1, but HTTP/1.1 is used by preference in all other
|
|
698
|
+
* cases.
|
|
699
|
+
*
|
|
700
|
+
* Client HTTP/2 support is only advertised as part of the TLS options.
|
|
701
|
+
* When no HTTPS configuration is provided, 'fallback' is equivalent to
|
|
702
|
+
* false.
|
|
703
|
+
*/
|
|
704
|
+
http2?: true | 'fallback' | false;
|
|
705
|
+
/**
|
|
706
|
+
* By default, requests that match no rules will receive an explanation of the
|
|
707
|
+
* request & existing rules, followed by some suggested example Mockttp code
|
|
708
|
+
* which could be used to match the rule.
|
|
709
|
+
*
|
|
710
|
+
* In some cases where the end client is unaware of Mockttp, these example
|
|
711
|
+
* suggestions are just confusing. Set `suggestChanges` to false to disable it.
|
|
712
|
+
*/
|
|
713
|
+
suggestChanges?: boolean;
|
|
714
|
+
/**
|
|
715
|
+
* Record the requests & response for all traffic matched by each rule, and make
|
|
716
|
+
* it available via endpoint.getSeenRequests().
|
|
717
|
+
*
|
|
718
|
+
* Defaults to true. It can be useful to set this to false if lots of data will
|
|
719
|
+
* be sent to/via the server, to avoid storing all traffic in memory unnecessarily,
|
|
720
|
+
* if getSeenRequests will not be used.
|
|
721
|
+
*
|
|
722
|
+
* If this is set to false then getSeenRequests() will always return
|
|
723
|
+
* an empty array. This only disables the built-in persistence of request data,
|
|
724
|
+
* so traffic can still be captured live or stored elsewhere using
|
|
725
|
+
* .on('request') & .on('response').
|
|
726
|
+
*/
|
|
727
|
+
recordTraffic?: boolean;
|
|
728
|
+
/**
|
|
729
|
+
* The maximum body size to process, in bytes.
|
|
730
|
+
*
|
|
731
|
+
* Bodies larger than this will be dropped, becoming empty, so they won't match
|
|
732
|
+
* body matchers, won't be available in .seenRequests, and won't be included in
|
|
733
|
+
* subscribed event data. Body data will still typically be included in passed
|
|
734
|
+
* through request & response data, in most cases, so this won't affect the
|
|
735
|
+
* external HTTP clients otherwise.
|
|
736
|
+
*/
|
|
737
|
+
maxBodySize?: number;
|
|
738
|
+
}
|
|
739
|
+
export type SubscribableEvent = 'request-initiated' | 'request' | 'response' | 'websocket-request' | 'websocket-accepted' | 'websocket-message-received' | 'websocket-message-sent' | 'websocket-close' | 'abort' | 'tls-passthrough-opened' | 'tls-passthrough-closed' | 'tls-client-error' | 'client-error' | 'rule-event';
|
|
740
|
+
/**
|
|
741
|
+
* @hidden
|
|
742
|
+
*/
|
|
743
|
+
export declare abstract class AbstractMockttp {
|
|
744
|
+
protected corsOptions: boolean | cors.CorsOptions;
|
|
745
|
+
protected debug: boolean;
|
|
746
|
+
protected recordTraffic: boolean;
|
|
747
|
+
protected suggestChanges: boolean;
|
|
748
|
+
abstract get url(): string;
|
|
749
|
+
abstract on(event: SubscribableEvent, callback: (req: CompletedRequest) => void): Promise<void>;
|
|
750
|
+
constructor(options: MockttpOptions);
|
|
751
|
+
get proxyEnv(): ProxyEnvConfig;
|
|
752
|
+
urlFor(path: string): string;
|
|
753
|
+
abstract addRequestRules: (...ruleData: RequestRuleData[]) => Promise<MockedEndpoint[]>;
|
|
754
|
+
addRequestRule: (rule: RequestRuleData) => Promise<MockedEndpoint>;
|
|
755
|
+
abstract setRequestRules(...ruleData: RequestRuleData[]): Promise<MockedEndpoint[]>;
|
|
756
|
+
abstract addWebSocketRules: (...ruleData: WebSocketRuleData[]) => Promise<MockedEndpoint[]>;
|
|
757
|
+
addWebSocketRule: (rule: WebSocketRuleData) => Promise<MockedEndpoint>;
|
|
758
|
+
abstract setWebSocketRules(...ruleData: WebSocketRuleData[]): Promise<MockedEndpoint[]>;
|
|
759
|
+
forAnyRequest(): RequestRuleBuilder;
|
|
760
|
+
forUnmatchedRequest(): RequestRuleBuilder;
|
|
761
|
+
forGet(url?: string | RegExp): RequestRuleBuilder;
|
|
762
|
+
forPost(url?: string | RegExp): RequestRuleBuilder;
|
|
763
|
+
forPut(url?: string | RegExp): RequestRuleBuilder;
|
|
764
|
+
forDelete(url?: string | RegExp): RequestRuleBuilder;
|
|
765
|
+
forPatch(url?: string | RegExp): RequestRuleBuilder;
|
|
766
|
+
forHead(url?: string | RegExp): RequestRuleBuilder;
|
|
767
|
+
forOptions(url?: string | RegExp): RequestRuleBuilder;
|
|
768
|
+
forJsonRpcRequest(match?: {
|
|
769
|
+
method?: string;
|
|
770
|
+
params?: any;
|
|
771
|
+
}): RequestRuleBuilder;
|
|
772
|
+
forAnyWebSocket(): WebSocketRuleBuilder;
|
|
773
|
+
}
|
|
774
|
+
//# sourceMappingURL=mockttp.d.ts.map
|