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.

Files changed (304) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +123 -3
  3. package/custom-typings/Function.d.ts +4 -0
  4. package/custom-typings/cors-gate.d.ts +13 -0
  5. package/custom-typings/http-proxy-agent.d.ts +9 -0
  6. package/custom-typings/node-type-extensions.d.ts +115 -0
  7. package/custom-typings/proxy-agent-modules.d.ts +5 -0
  8. package/custom-typings/request-promise-native.d.ts +28 -0
  9. package/custom-typings/zstd-codec.d.ts +20 -0
  10. package/dist/admin/admin-bin.d.ts +3 -0
  11. package/dist/admin/admin-bin.d.ts.map +1 -0
  12. package/dist/admin/admin-bin.js +61 -0
  13. package/dist/admin/admin-bin.js.map +1 -0
  14. package/dist/admin/admin-plugin-types.d.ts +29 -0
  15. package/dist/admin/admin-plugin-types.d.ts.map +1 -0
  16. package/dist/admin/admin-plugin-types.js +3 -0
  17. package/dist/admin/admin-plugin-types.js.map +1 -0
  18. package/dist/admin/admin-server.d.ts +98 -0
  19. package/dist/admin/admin-server.d.ts.map +1 -0
  20. package/dist/admin/admin-server.js +426 -0
  21. package/dist/admin/admin-server.js.map +1 -0
  22. package/dist/admin/graphql-utils.d.ts +4 -0
  23. package/dist/admin/graphql-utils.d.ts.map +1 -0
  24. package/dist/admin/graphql-utils.js +28 -0
  25. package/dist/admin/graphql-utils.js.map +1 -0
  26. package/dist/admin/mockttp-admin-model.d.ts +7 -0
  27. package/dist/admin/mockttp-admin-model.d.ts.map +1 -0
  28. package/dist/admin/mockttp-admin-model.js +214 -0
  29. package/dist/admin/mockttp-admin-model.js.map +1 -0
  30. package/dist/admin/mockttp-admin-plugin.d.ts +28 -0
  31. package/dist/admin/mockttp-admin-plugin.d.ts.map +1 -0
  32. package/dist/admin/mockttp-admin-plugin.js +37 -0
  33. package/dist/admin/mockttp-admin-plugin.js.map +1 -0
  34. package/dist/admin/mockttp-admin-server.d.ts +16 -0
  35. package/dist/admin/mockttp-admin-server.d.ts.map +1 -0
  36. package/dist/admin/mockttp-admin-server.js +17 -0
  37. package/dist/admin/mockttp-admin-server.js.map +1 -0
  38. package/dist/admin/mockttp-schema.d.ts +2 -0
  39. package/dist/admin/mockttp-schema.d.ts.map +1 -0
  40. package/dist/admin/mockttp-schema.js +225 -0
  41. package/dist/admin/mockttp-schema.js.map +1 -0
  42. package/dist/client/admin-client.d.ts +112 -0
  43. package/dist/client/admin-client.d.ts.map +1 -0
  44. package/dist/client/admin-client.js +511 -0
  45. package/dist/client/admin-client.js.map +1 -0
  46. package/dist/client/admin-query.d.ts +13 -0
  47. package/dist/client/admin-query.d.ts.map +1 -0
  48. package/dist/client/admin-query.js +26 -0
  49. package/dist/client/admin-query.js.map +1 -0
  50. package/dist/client/mocked-endpoint-client.d.ts +12 -0
  51. package/dist/client/mocked-endpoint-client.d.ts.map +1 -0
  52. package/dist/client/mocked-endpoint-client.js +33 -0
  53. package/dist/client/mocked-endpoint-client.js.map +1 -0
  54. package/dist/client/mockttp-admin-request-builder.d.ts +38 -0
  55. package/dist/client/mockttp-admin-request-builder.d.ts.map +1 -0
  56. package/dist/client/mockttp-admin-request-builder.js +462 -0
  57. package/dist/client/mockttp-admin-request-builder.js.map +1 -0
  58. package/dist/client/mockttp-client.d.ts +56 -0
  59. package/dist/client/mockttp-client.d.ts.map +1 -0
  60. package/dist/client/mockttp-client.js +112 -0
  61. package/dist/client/mockttp-client.js.map +1 -0
  62. package/dist/client/schema-introspection.d.ts +11 -0
  63. package/dist/client/schema-introspection.d.ts.map +1 -0
  64. package/dist/client/schema-introspection.js +128 -0
  65. package/dist/client/schema-introspection.js.map +1 -0
  66. package/dist/main.browser.d.ts +49 -0
  67. package/dist/main.browser.d.ts.map +1 -0
  68. package/dist/main.browser.js +57 -0
  69. package/dist/main.browser.js.map +1 -0
  70. package/dist/main.d.ts +86 -0
  71. package/dist/main.d.ts.map +1 -0
  72. package/dist/main.js +108 -0
  73. package/dist/main.js.map +1 -0
  74. package/dist/mockttp.d.ts +774 -0
  75. package/dist/mockttp.d.ts.map +1 -0
  76. package/dist/mockttp.js +81 -0
  77. package/dist/mockttp.js.map +1 -0
  78. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts +5 -0
  79. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts.map +1 -0
  80. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js +12 -0
  81. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js.map +1 -0
  82. package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts +8 -0
  83. package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts.map +1 -0
  84. package/dist/pluggable-admin-api/mockttp-pluggable-admin.js +13 -0
  85. package/dist/pluggable-admin-api/mockttp-pluggable-admin.js.map +1 -0
  86. package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts +6 -0
  87. package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts.map +1 -0
  88. package/dist/pluggable-admin-api/pluggable-admin.browser.js +13 -0
  89. package/dist/pluggable-admin-api/pluggable-admin.browser.js.map +1 -0
  90. package/dist/pluggable-admin-api/pluggable-admin.d.ts +18 -0
  91. package/dist/pluggable-admin-api/pluggable-admin.d.ts.map +1 -0
  92. package/dist/pluggable-admin-api/pluggable-admin.js +20 -0
  93. package/dist/pluggable-admin-api/pluggable-admin.js.map +1 -0
  94. package/dist/rules/base-rule-builder.d.ts +185 -0
  95. package/dist/rules/base-rule-builder.d.ts.map +1 -0
  96. package/dist/rules/base-rule-builder.js +251 -0
  97. package/dist/rules/base-rule-builder.js.map +1 -0
  98. package/dist/rules/completion-checkers.d.ts +41 -0
  99. package/dist/rules/completion-checkers.d.ts.map +1 -0
  100. package/dist/rules/completion-checkers.js +87 -0
  101. package/dist/rules/completion-checkers.js.map +1 -0
  102. package/dist/rules/http-agents.d.ts +11 -0
  103. package/dist/rules/http-agents.d.ts.map +1 -0
  104. package/dist/rules/http-agents.js +91 -0
  105. package/dist/rules/http-agents.js.map +1 -0
  106. package/dist/rules/matchers.d.ts +214 -0
  107. package/dist/rules/matchers.d.ts.map +1 -0
  108. package/dist/rules/matchers.js +515 -0
  109. package/dist/rules/matchers.js.map +1 -0
  110. package/dist/rules/passthrough-handling-definitions.d.ts +106 -0
  111. package/dist/rules/passthrough-handling-definitions.d.ts.map +1 -0
  112. package/dist/rules/passthrough-handling-definitions.js +3 -0
  113. package/dist/rules/passthrough-handling-definitions.js.map +1 -0
  114. package/dist/rules/passthrough-handling.d.ts +33 -0
  115. package/dist/rules/passthrough-handling.d.ts.map +1 -0
  116. package/dist/rules/passthrough-handling.js +294 -0
  117. package/dist/rules/passthrough-handling.js.map +1 -0
  118. package/dist/rules/proxy-config.d.ts +76 -0
  119. package/dist/rules/proxy-config.d.ts.map +1 -0
  120. package/dist/rules/proxy-config.js +48 -0
  121. package/dist/rules/proxy-config.js.map +1 -0
  122. package/dist/rules/requests/request-handler-definitions.d.ts +600 -0
  123. package/dist/rules/requests/request-handler-definitions.d.ts.map +1 -0
  124. package/dist/rules/requests/request-handler-definitions.js +423 -0
  125. package/dist/rules/requests/request-handler-definitions.js.map +1 -0
  126. package/dist/rules/requests/request-handlers.d.ts +65 -0
  127. package/dist/rules/requests/request-handlers.d.ts.map +1 -0
  128. package/dist/rules/requests/request-handlers.js +1014 -0
  129. package/dist/rules/requests/request-handlers.js.map +1 -0
  130. package/dist/rules/requests/request-rule-builder.d.ts +255 -0
  131. package/dist/rules/requests/request-rule-builder.d.ts.map +1 -0
  132. package/dist/rules/requests/request-rule-builder.js +340 -0
  133. package/dist/rules/requests/request-rule-builder.js.map +1 -0
  134. package/dist/rules/requests/request-rule.d.ts +36 -0
  135. package/dist/rules/requests/request-rule.d.ts.map +1 -0
  136. package/dist/rules/requests/request-rule.js +100 -0
  137. package/dist/rules/requests/request-rule.js.map +1 -0
  138. package/dist/rules/rule-deserialization.d.ts +8 -0
  139. package/dist/rules/rule-deserialization.d.ts.map +1 -0
  140. package/dist/rules/rule-deserialization.js +27 -0
  141. package/dist/rules/rule-deserialization.js.map +1 -0
  142. package/dist/rules/rule-parameters.d.ts +21 -0
  143. package/dist/rules/rule-parameters.d.ts.map +1 -0
  144. package/dist/rules/rule-parameters.js +31 -0
  145. package/dist/rules/rule-parameters.js.map +1 -0
  146. package/dist/rules/rule-serialization.d.ts +7 -0
  147. package/dist/rules/rule-serialization.d.ts.map +1 -0
  148. package/dist/rules/rule-serialization.js +25 -0
  149. package/dist/rules/rule-serialization.js.map +1 -0
  150. package/dist/rules/websockets/websocket-handler-definitions.d.ts +78 -0
  151. package/dist/rules/websockets/websocket-handler-definitions.d.ts.map +1 -0
  152. package/dist/rules/websockets/websocket-handler-definitions.js +118 -0
  153. package/dist/rules/websockets/websocket-handler-definitions.js.map +1 -0
  154. package/dist/rules/websockets/websocket-handlers.d.ts +39 -0
  155. package/dist/rules/websockets/websocket-handlers.d.ts.map +1 -0
  156. package/dist/rules/websockets/websocket-handlers.js +356 -0
  157. package/dist/rules/websockets/websocket-handlers.js.map +1 -0
  158. package/dist/rules/websockets/websocket-rule-builder.d.ts +173 -0
  159. package/dist/rules/websockets/websocket-rule-builder.d.ts.map +1 -0
  160. package/dist/rules/websockets/websocket-rule-builder.js +232 -0
  161. package/dist/rules/websockets/websocket-rule-builder.js.map +1 -0
  162. package/dist/rules/websockets/websocket-rule.d.ts +34 -0
  163. package/dist/rules/websockets/websocket-rule.d.ts.map +1 -0
  164. package/dist/rules/websockets/websocket-rule.js +87 -0
  165. package/dist/rules/websockets/websocket-rule.js.map +1 -0
  166. package/dist/serialization/body-serialization.d.ts +43 -0
  167. package/dist/serialization/body-serialization.d.ts.map +1 -0
  168. package/dist/serialization/body-serialization.js +70 -0
  169. package/dist/serialization/body-serialization.js.map +1 -0
  170. package/dist/serialization/serialization.d.ts +63 -0
  171. package/dist/serialization/serialization.d.ts.map +1 -0
  172. package/dist/serialization/serialization.js +263 -0
  173. package/dist/serialization/serialization.js.map +1 -0
  174. package/dist/server/http-combo-server.d.ts +13 -0
  175. package/dist/server/http-combo-server.d.ts.map +1 -0
  176. package/dist/server/http-combo-server.js +330 -0
  177. package/dist/server/http-combo-server.js.map +1 -0
  178. package/dist/server/mocked-endpoint.d.ts +14 -0
  179. package/dist/server/mocked-endpoint.d.ts.map +1 -0
  180. package/dist/server/mocked-endpoint.js +40 -0
  181. package/dist/server/mocked-endpoint.js.map +1 -0
  182. package/dist/server/mockttp-server.d.ts +87 -0
  183. package/dist/server/mockttp-server.d.ts.map +1 -0
  184. package/dist/server/mockttp-server.js +859 -0
  185. package/dist/server/mockttp-server.js.map +1 -0
  186. package/dist/types.d.ts +359 -0
  187. package/dist/types.d.ts.map +1 -0
  188. package/dist/types.js +20 -0
  189. package/dist/types.js.map +1 -0
  190. package/dist/util/buffer-utils.d.ts +13 -0
  191. package/dist/util/buffer-utils.d.ts.map +1 -0
  192. package/dist/util/buffer-utils.js +141 -0
  193. package/dist/util/buffer-utils.js.map +1 -0
  194. package/dist/util/dns.d.ts +11 -0
  195. package/dist/util/dns.d.ts.map +1 -0
  196. package/dist/util/dns.js +47 -0
  197. package/dist/util/dns.js.map +1 -0
  198. package/dist/util/error.d.ts +9 -0
  199. package/dist/util/error.d.ts.map +1 -0
  200. package/dist/util/error.js +11 -0
  201. package/dist/util/error.js.map +1 -0
  202. package/dist/util/header-utils.d.ts +35 -0
  203. package/dist/util/header-utils.d.ts.map +1 -0
  204. package/dist/util/header-utils.js +200 -0
  205. package/dist/util/header-utils.js.map +1 -0
  206. package/dist/util/openssl-compat.d.ts +2 -0
  207. package/dist/util/openssl-compat.d.ts.map +1 -0
  208. package/dist/util/openssl-compat.js +26 -0
  209. package/dist/util/openssl-compat.js.map +1 -0
  210. package/dist/util/promise.d.ts +10 -0
  211. package/dist/util/promise.d.ts.map +1 -0
  212. package/dist/util/promise.js +25 -0
  213. package/dist/util/promise.js.map +1 -0
  214. package/dist/util/request-utils.d.ts +46 -0
  215. package/dist/util/request-utils.d.ts.map +1 -0
  216. package/dist/util/request-utils.js +462 -0
  217. package/dist/util/request-utils.js.map +1 -0
  218. package/dist/util/server-utils.d.ts +2 -0
  219. package/dist/util/server-utils.d.ts.map +1 -0
  220. package/dist/util/server-utils.js +14 -0
  221. package/dist/util/server-utils.js.map +1 -0
  222. package/dist/util/socket-util.d.ts +28 -0
  223. package/dist/util/socket-util.d.ts.map +1 -0
  224. package/dist/util/socket-util.js +174 -0
  225. package/dist/util/socket-util.js.map +1 -0
  226. package/dist/util/tls.d.ts +68 -0
  227. package/dist/util/tls.d.ts.map +1 -0
  228. package/dist/util/tls.js +220 -0
  229. package/dist/util/tls.js.map +1 -0
  230. package/dist/util/type-utils.d.ts +14 -0
  231. package/dist/util/type-utils.d.ts.map +1 -0
  232. package/dist/util/type-utils.js +3 -0
  233. package/dist/util/type-utils.js.map +1 -0
  234. package/dist/util/url.d.ts +17 -0
  235. package/dist/util/url.d.ts.map +1 -0
  236. package/dist/util/url.js +96 -0
  237. package/dist/util/url.js.map +1 -0
  238. package/dist/util/util.d.ts +8 -0
  239. package/dist/util/util.d.ts.map +1 -0
  240. package/dist/util/util.js +41 -0
  241. package/dist/util/util.js.map +1 -0
  242. package/docs/api-docs-landing-page.md +11 -0
  243. package/docs/runkitExample.js +16 -0
  244. package/docs/setup.md +136 -0
  245. package/nfyb8qx5.cjs +1 -0
  246. package/package.json +194 -4
  247. package/src/admin/admin-bin.ts +62 -0
  248. package/src/admin/admin-plugin-types.ts +29 -0
  249. package/src/admin/admin-server.ts +619 -0
  250. package/src/admin/graphql-utils.ts +28 -0
  251. package/src/admin/mockttp-admin-model.ts +264 -0
  252. package/src/admin/mockttp-admin-plugin.ts +59 -0
  253. package/src/admin/mockttp-admin-server.ts +27 -0
  254. package/src/admin/mockttp-schema.ts +222 -0
  255. package/src/client/admin-client.ts +652 -0
  256. package/src/client/admin-query.ts +52 -0
  257. package/src/client/mocked-endpoint-client.ts +32 -0
  258. package/src/client/mockttp-admin-request-builder.ts +540 -0
  259. package/src/client/mockttp-client.ts +178 -0
  260. package/src/client/schema-introspection.ts +131 -0
  261. package/src/main.browser.ts +60 -0
  262. package/src/main.ts +160 -0
  263. package/src/mockttp.ts +926 -0
  264. package/src/pluggable-admin-api/mockttp-pluggable-admin.browser.ts +7 -0
  265. package/src/pluggable-admin-api/mockttp-pluggable-admin.ts +13 -0
  266. package/src/pluggable-admin-api/pluggable-admin.browser.ts +9 -0
  267. package/src/pluggable-admin-api/pluggable-admin.ts +36 -0
  268. package/src/rules/base-rule-builder.ts +312 -0
  269. package/src/rules/completion-checkers.ts +90 -0
  270. package/src/rules/http-agents.ts +119 -0
  271. package/src/rules/matchers.ts +665 -0
  272. package/src/rules/passthrough-handling-definitions.ts +111 -0
  273. package/src/rules/passthrough-handling.ts +376 -0
  274. package/src/rules/proxy-config.ts +136 -0
  275. package/src/rules/requests/request-handler-definitions.ts +1089 -0
  276. package/src/rules/requests/request-handlers.ts +1369 -0
  277. package/src/rules/requests/request-rule-builder.ts +481 -0
  278. package/src/rules/requests/request-rule.ts +148 -0
  279. package/src/rules/rule-deserialization.ts +55 -0
  280. package/src/rules/rule-parameters.ts +41 -0
  281. package/src/rules/rule-serialization.ts +29 -0
  282. package/src/rules/websockets/websocket-handler-definitions.ts +196 -0
  283. package/src/rules/websockets/websocket-handlers.ts +509 -0
  284. package/src/rules/websockets/websocket-rule-builder.ts +275 -0
  285. package/src/rules/websockets/websocket-rule.ts +136 -0
  286. package/src/serialization/body-serialization.ts +84 -0
  287. package/src/serialization/serialization.ts +373 -0
  288. package/src/server/http-combo-server.ts +424 -0
  289. package/src/server/mocked-endpoint.ts +44 -0
  290. package/src/server/mockttp-server.ts +1110 -0
  291. package/src/types.ts +433 -0
  292. package/src/util/buffer-utils.ts +164 -0
  293. package/src/util/dns.ts +52 -0
  294. package/src/util/error.ts +18 -0
  295. package/src/util/header-utils.ts +220 -0
  296. package/src/util/openssl-compat.ts +26 -0
  297. package/src/util/promise.ts +31 -0
  298. package/src/util/request-utils.ts +607 -0
  299. package/src/util/server-utils.ts +18 -0
  300. package/src/util/socket-util.ts +193 -0
  301. package/src/util/tls.ts +348 -0
  302. package/src/util/type-utils.ts +15 -0
  303. package/src/util/url.ts +113 -0
  304. 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