@counterfact/client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/License.md +21 -0
- package/README.md +46 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/raw-http-client.d.ts +35 -0
- package/dist/raw-http-client.js +191 -0
- package/dist/route-builder.d.ts +116 -0
- package/dist/route-builder.js +330 -0
- package/dist/route-catalog.d.ts +40 -0
- package/dist/route-catalog.js +21 -0
- package/examples/reusable-request.mjs +46 -0
- package/package.json +54 -0
package/License.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Patrick McElhaney
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# `@counterfact/client`
|
|
2
|
+
|
|
3
|
+
Counterfact's raw HTTP client and immutable, OpenAPI-aware request builder.
|
|
4
|
+
Use it to construct, inspect, reuse, and send requests without starting the
|
|
5
|
+
Counterfact REPL or simulator.
|
|
6
|
+
|
|
7
|
+
## Reusable requests
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {
|
|
11
|
+
createOpenApiRouteCatalog,
|
|
12
|
+
createRouteFunction,
|
|
13
|
+
} from "@counterfact/client";
|
|
14
|
+
|
|
15
|
+
const catalog = createOpenApiRouteCatalog({
|
|
16
|
+
paths: {
|
|
17
|
+
"/pets/{petId}": {
|
|
18
|
+
get: {
|
|
19
|
+
parameters: [
|
|
20
|
+
{
|
|
21
|
+
in: "path",
|
|
22
|
+
name: "petId",
|
|
23
|
+
required: true,
|
|
24
|
+
type: "integer",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
responses: { 200: { description: "A pet" } },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const route = createRouteFunction(3000, "localhost", catalog);
|
|
34
|
+
const pet = route("/pets/{petId}").method("get").path({ petId: 42 });
|
|
35
|
+
|
|
36
|
+
console.log(pet.ready());
|
|
37
|
+
console.log(pet.help());
|
|
38
|
+
await pet.send();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Builder methods are immutable: calling `path()`, `query()`, `headers()`,
|
|
42
|
+
`body()`, or `method()` returns a new builder, so a common request can be
|
|
43
|
+
safely branched into reusable variants.
|
|
44
|
+
|
|
45
|
+
See [`examples/reusable-request.mjs`](./examples/reusable-request.mjs) for a
|
|
46
|
+
complete example with a local HTTP server.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { RawHttpClient } from "./raw-http-client.js";
|
|
2
|
+
export { RouteBuilder, createRouteFunction, type MissingParam, type MissingParams, type RouteBuilderOptions, type RouteParams, } from "./route-builder.js";
|
|
3
|
+
export { createOpenApiRouteCatalog, type OpenApiRouteDocument, type RouteCatalog, type RouteOperation, type RouteParameter, } from "./route-catalog.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal HTTP/1.1 client that communicates over a raw TCP socket.
|
|
3
|
+
*
|
|
4
|
+
* Used in the Counterfact REPL (`client.*`) to send requests to the local mock
|
|
5
|
+
* server and pretty-print the request and response to `stdout` with ANSI
|
|
6
|
+
* colours.
|
|
7
|
+
*
|
|
8
|
+
* Unlike `fetch` or Axios, `RawHttpClient` does not buffer or parse the
|
|
9
|
+
* response — the raw HTTP response string is returned from every method.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RawHttpClient {
|
|
12
|
+
#private;
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
requestNumber: number;
|
|
16
|
+
constructor(host?: string, port?: number);
|
|
17
|
+
/** Sends a `GET` request and returns the raw HTTP response string. */
|
|
18
|
+
get(path: string, headers?: {}): Promise<string>;
|
|
19
|
+
/** Sends a `HEAD` request and returns the raw HTTP response string. */
|
|
20
|
+
head(path: string, headers?: {}): Promise<string>;
|
|
21
|
+
/** Sends a `POST` request with `body` and returns the raw HTTP response string. */
|
|
22
|
+
post(path: string, body?: string | object, headers?: {}): Promise<string>;
|
|
23
|
+
/** Sends a `PUT` request with `body` and returns the raw HTTP response string. */
|
|
24
|
+
put(path: string, body?: string | object, headers?: {}): Promise<string>;
|
|
25
|
+
/** Sends a `DELETE` request and returns the raw HTTP response string. */
|
|
26
|
+
delete(path: string, headers?: {}): Promise<string>;
|
|
27
|
+
/** Sends a `CONNECT` request and returns the raw HTTP response string. */
|
|
28
|
+
connect(path: string, headers?: {}): Promise<string>;
|
|
29
|
+
/** Sends an `OPTIONS` request and returns the raw HTTP response string. */
|
|
30
|
+
options(path: string, headers?: {}): Promise<string>;
|
|
31
|
+
/** Sends a `TRACE` request and returns the raw HTTP response string. */
|
|
32
|
+
trace(path: string, headers?: {}): Promise<string>;
|
|
33
|
+
/** Sends a `PATCH` request with `body` and returns the raw HTTP response string. */
|
|
34
|
+
patch(path: string, body?: string | object, headers?: {}): Promise<string>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
const colors = {
|
|
3
|
+
reset: "\x1b[0m",
|
|
4
|
+
dim: "\x1b[2m",
|
|
5
|
+
cyan: "\x1b[36m",
|
|
6
|
+
green: "\x1b[32m",
|
|
7
|
+
yellow: "\x1b[33m",
|
|
8
|
+
red: "\x1b[31m",
|
|
9
|
+
bold: "\x1b[1m",
|
|
10
|
+
magenta: "\x1b[35m",
|
|
11
|
+
blue: "\x1b[34m",
|
|
12
|
+
};
|
|
13
|
+
function isLikelyJson(headersBlock, body) {
|
|
14
|
+
const m = headersBlock.match(/^content-type:\s*(?<contentType>[^\r\n;]+)/im);
|
|
15
|
+
const ct = (m?.groups?.["contentType"] ?? "").toLowerCase();
|
|
16
|
+
if (ct.includes("application/json") || ct.includes("+json"))
|
|
17
|
+
return true;
|
|
18
|
+
const s = body.trim();
|
|
19
|
+
if (!s)
|
|
20
|
+
return false;
|
|
21
|
+
return ((s.startsWith("{") && s.endsWith("}")) ||
|
|
22
|
+
(s.startsWith("[") && s.endsWith("]")));
|
|
23
|
+
}
|
|
24
|
+
function highlightJson(text) {
|
|
25
|
+
let obj;
|
|
26
|
+
try {
|
|
27
|
+
obj = JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return text;
|
|
31
|
+
}
|
|
32
|
+
const pretty = JSON.stringify(obj, null, 2);
|
|
33
|
+
return pretty.replace(
|
|
34
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- This alternation is linear: the quoted-string branch consumes either an escaped pair (`\\.`) or one non-quote/non-backslash char per iteration, so it cannot catastrophically backtrack.
|
|
35
|
+
/(?<str>"(?:\\.|[^"\\])*")(?<colon>\s*:)?|\b(?<boolOrNull>true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g, (match, str, colon, boolOrNull) => {
|
|
36
|
+
if (str) {
|
|
37
|
+
if (colon)
|
|
38
|
+
return `${colors.blue}${str}${colors.reset}${colon}`;
|
|
39
|
+
return `${colors.green}${str}${colors.reset}`;
|
|
40
|
+
}
|
|
41
|
+
if (boolOrNull) {
|
|
42
|
+
return `${colors.magenta}${match}${colors.reset}`;
|
|
43
|
+
}
|
|
44
|
+
return `${colors.yellow}${match}${colors.reset}`;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function stringifyBody(body) {
|
|
48
|
+
if (typeof body === "string") {
|
|
49
|
+
return body;
|
|
50
|
+
}
|
|
51
|
+
if (typeof body === "undefined") {
|
|
52
|
+
return body;
|
|
53
|
+
}
|
|
54
|
+
return JSON.stringify(body);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A minimal HTTP/1.1 client that communicates over a raw TCP socket.
|
|
58
|
+
*
|
|
59
|
+
* Used in the Counterfact REPL (`client.*`) to send requests to the local mock
|
|
60
|
+
* server and pretty-print the request and response to `stdout` with ANSI
|
|
61
|
+
* colours.
|
|
62
|
+
*
|
|
63
|
+
* Unlike `fetch` or Axios, `RawHttpClient` does not buffer or parse the
|
|
64
|
+
* response — the raw HTTP response string is returned from every method.
|
|
65
|
+
*/
|
|
66
|
+
export class RawHttpClient {
|
|
67
|
+
host;
|
|
68
|
+
port;
|
|
69
|
+
requestNumber = 0;
|
|
70
|
+
constructor(host = "localhost", port = 80) {
|
|
71
|
+
this.host = host;
|
|
72
|
+
this.port = port;
|
|
73
|
+
}
|
|
74
|
+
/** Sends a `GET` request and returns the raw HTTP response string. */
|
|
75
|
+
get(path, headers = {}) {
|
|
76
|
+
return this.#send("GET", path, "", headers);
|
|
77
|
+
}
|
|
78
|
+
/** Sends a `HEAD` request and returns the raw HTTP response string. */
|
|
79
|
+
head(path, headers = {}) {
|
|
80
|
+
return this.#send("HEAD", path, "", headers);
|
|
81
|
+
}
|
|
82
|
+
/** Sends a `POST` request with `body` and returns the raw HTTP response string. */
|
|
83
|
+
post(path, body = "", headers = {}) {
|
|
84
|
+
return this.#send("POST", path, body, headers);
|
|
85
|
+
}
|
|
86
|
+
/** Sends a `PUT` request with `body` and returns the raw HTTP response string. */
|
|
87
|
+
put(path, body = "", headers = {}) {
|
|
88
|
+
return this.#send("PUT", path, body, headers);
|
|
89
|
+
}
|
|
90
|
+
/** Sends a `DELETE` request and returns the raw HTTP response string. */
|
|
91
|
+
delete(path, headers = {}) {
|
|
92
|
+
return this.#send("DELETE", path, "", headers);
|
|
93
|
+
}
|
|
94
|
+
/** Sends a `CONNECT` request and returns the raw HTTP response string. */
|
|
95
|
+
connect(path, headers = {}) {
|
|
96
|
+
return this.#send("CONNECT", path, "", headers);
|
|
97
|
+
}
|
|
98
|
+
/** Sends an `OPTIONS` request and returns the raw HTTP response string. */
|
|
99
|
+
options(path, headers = {}) {
|
|
100
|
+
return this.#send("OPTIONS", path, "", headers);
|
|
101
|
+
}
|
|
102
|
+
/** Sends a `TRACE` request and returns the raw HTTP response string. */
|
|
103
|
+
trace(path, headers = {}) {
|
|
104
|
+
return this.#send("TRACE", path, "", headers);
|
|
105
|
+
}
|
|
106
|
+
/** Sends a `PATCH` request with `body` and returns the raw HTTP response string. */
|
|
107
|
+
patch(path, body = "", headers = {}) {
|
|
108
|
+
return this.#send("PATCH", path, body, headers);
|
|
109
|
+
}
|
|
110
|
+
#send(method, path, bodyAsStringOrObject, headers) {
|
|
111
|
+
const requestNumber = ++this.requestNumber;
|
|
112
|
+
const body = stringifyBody(bodyAsStringOrObject);
|
|
113
|
+
const effectiveHeaders = { ...headers };
|
|
114
|
+
if (typeof bodyAsStringOrObject === "object" &&
|
|
115
|
+
bodyAsStringOrObject !== null &&
|
|
116
|
+
!Object.keys(effectiveHeaders).some((k) => k.toLowerCase() === "content-type")) {
|
|
117
|
+
effectiveHeaders["Content-Type"] = "application/json";
|
|
118
|
+
}
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const socket = net.createConnection({ host: this.host, port: this.port }, () => {
|
|
121
|
+
let request = `${method} ${path} HTTP/1.1\r\n`;
|
|
122
|
+
request += `Host: ${this.host}\r\n`;
|
|
123
|
+
request += `Connection: close\r\n`;
|
|
124
|
+
if (body != null) {
|
|
125
|
+
request += `Content-Length: ${Buffer.byteLength(body)}\r\n`;
|
|
126
|
+
}
|
|
127
|
+
for (const [key, value] of Object.entries(effectiveHeaders)) {
|
|
128
|
+
request += `${key}: ${value}\r\n`;
|
|
129
|
+
}
|
|
130
|
+
request += `\r\n`;
|
|
131
|
+
if (body != null)
|
|
132
|
+
request += body;
|
|
133
|
+
this.#printRequest(request, requestNumber);
|
|
134
|
+
socket.write(request);
|
|
135
|
+
});
|
|
136
|
+
const chunks = [];
|
|
137
|
+
socket.on("data", (chunk) => {
|
|
138
|
+
chunks.push(chunk);
|
|
139
|
+
});
|
|
140
|
+
socket.on("end", () => {
|
|
141
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
142
|
+
this.#printResponse(raw, requestNumber);
|
|
143
|
+
process.stdout.write(`${colors.bold}⬣> ${colors.reset}`);
|
|
144
|
+
resolve(raw);
|
|
145
|
+
});
|
|
146
|
+
socket.on("error", reject);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
#printRequest(raw, requestNumber) {
|
|
150
|
+
const [head = "", body = ""] = raw.split("\r\n\r\n");
|
|
151
|
+
const lines = head.split("\r\n");
|
|
152
|
+
process.stdout.write(`${colors.cyan}\n----- REQUEST #${requestNumber} -----${colors.reset}\n`);
|
|
153
|
+
process.stdout.write(`${colors.cyan}${lines[0]}${colors.reset}\n`);
|
|
154
|
+
for (const line of lines.slice(1)) {
|
|
155
|
+
process.stdout.write(`${colors.dim}${line}${colors.reset}\n`);
|
|
156
|
+
}
|
|
157
|
+
if (body) {
|
|
158
|
+
process.stdout.write("\n");
|
|
159
|
+
const outBody = isLikelyJson(head.toLowerCase(), body)
|
|
160
|
+
? highlightJson(body)
|
|
161
|
+
: body;
|
|
162
|
+
process.stdout.write(outBody + "\n");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
#printResponse(raw, requestNumber) {
|
|
166
|
+
const [head = "", body = ""] = raw.split("\r\n\r\n");
|
|
167
|
+
const lines = head.split("\r\n");
|
|
168
|
+
const statusLine = lines[0] ?? "";
|
|
169
|
+
let statusColor = colors.green;
|
|
170
|
+
const match = statusLine.match(/HTTP\/\d+\.\d+\s+(?<statusCode>\d+)/);
|
|
171
|
+
if (match) {
|
|
172
|
+
const code = Number(match.groups?.["statusCode"]);
|
|
173
|
+
if (code >= 400)
|
|
174
|
+
statusColor = colors.red;
|
|
175
|
+
else if (code >= 300)
|
|
176
|
+
statusColor = colors.yellow;
|
|
177
|
+
}
|
|
178
|
+
process.stdout.write(`\n${statusColor}----- RESPONSE #${requestNumber} -----${colors.reset}\n`);
|
|
179
|
+
process.stdout.write(`${statusColor}${statusLine}${colors.reset}\n`);
|
|
180
|
+
for (const line of lines.slice(1)) {
|
|
181
|
+
process.stdout.write(`${colors.dim}${line}${colors.reset}\n`);
|
|
182
|
+
}
|
|
183
|
+
if (body) {
|
|
184
|
+
process.stdout.write("\n");
|
|
185
|
+
const outBody = isLikelyJson(head.toLowerCase(), body)
|
|
186
|
+
? highlightJson(body)
|
|
187
|
+
: body;
|
|
188
|
+
process.stdout.write(outBody + "\n");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { RouteCatalog } from "./route-catalog.js";
|
|
2
|
+
export type RouteParams = Record<string, boolean | number | string>;
|
|
3
|
+
export interface MissingParam {
|
|
4
|
+
description?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MissingParams {
|
|
9
|
+
header?: MissingParam[];
|
|
10
|
+
path?: MissingParam[];
|
|
11
|
+
query?: MissingParam[];
|
|
12
|
+
}
|
|
13
|
+
export interface RouteBuilderOptions {
|
|
14
|
+
body?: unknown;
|
|
15
|
+
headerParams?: RouteParams;
|
|
16
|
+
host?: string;
|
|
17
|
+
method?: string;
|
|
18
|
+
pathParams?: RouteParams;
|
|
19
|
+
port: number;
|
|
20
|
+
queryParams?: RouteParams;
|
|
21
|
+
routeCatalog?: RouteCatalog;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Immutable fluent builder for constructing and sending HTTP requests from the
|
|
25
|
+
* Counterfact REPL.
|
|
26
|
+
*
|
|
27
|
+
* Each builder method returns a **new** `RouteBuilder` instance with the
|
|
28
|
+
* updated field — the original is never mutated. When all required parameters
|
|
29
|
+
* are set, call {@link send} to execute the request.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* // Inside the REPL:
|
|
33
|
+
* route("/pets/{petId}").method("get").path({ petId: 1 }).send();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class RouteBuilder {
|
|
37
|
+
readonly routePath: string;
|
|
38
|
+
private readonly _body;
|
|
39
|
+
private readonly _headerParams;
|
|
40
|
+
private readonly _host;
|
|
41
|
+
private readonly _method;
|
|
42
|
+
private readonly _routeCatalog;
|
|
43
|
+
private readonly _pathParams;
|
|
44
|
+
private readonly _port;
|
|
45
|
+
private readonly _queryParams;
|
|
46
|
+
private readonly _operation;
|
|
47
|
+
constructor(routePath: string, options: RouteBuilderOptions);
|
|
48
|
+
private _resolveOperation;
|
|
49
|
+
private clone;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a new builder with the HTTP method set.
|
|
52
|
+
*
|
|
53
|
+
* @param method - HTTP method name (case-insensitive, e.g. `"get"`, `"POST"`).
|
|
54
|
+
*/
|
|
55
|
+
method(method: string): RouteBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Returns a new builder with additional path parameters merged in.
|
|
58
|
+
*
|
|
59
|
+
* @param params - Key/value map of path variable names to values.
|
|
60
|
+
*/
|
|
61
|
+
path(params: RouteParams): RouteBuilder;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a new builder with additional query parameters merged in.
|
|
64
|
+
*
|
|
65
|
+
* @param params - Key/value map of query parameter names to values.
|
|
66
|
+
*/
|
|
67
|
+
query(params: RouteParams): RouteBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a new builder with additional request headers merged in.
|
|
70
|
+
*
|
|
71
|
+
* @param params - Key/value map of header names to values.
|
|
72
|
+
*/
|
|
73
|
+
headers(params: RouteParams): RouteBuilder;
|
|
74
|
+
/**
|
|
75
|
+
* Returns a new builder with the request body set.
|
|
76
|
+
*
|
|
77
|
+
* @param body - The request body (will be serialised to JSON or sent as-is).
|
|
78
|
+
*/
|
|
79
|
+
body(body: unknown): RouteBuilder;
|
|
80
|
+
private getOperation;
|
|
81
|
+
/**
|
|
82
|
+
* Returns `true` when a method is set and no required parameters are
|
|
83
|
+
* missing.
|
|
84
|
+
*/
|
|
85
|
+
ready(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a {@link MissingParams} object describing all required parameters
|
|
88
|
+
* that have not yet been set, or `undefined` when nothing is missing (or
|
|
89
|
+
* when the operation has no parameters).
|
|
90
|
+
*/
|
|
91
|
+
missing(): MissingParams | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Returns a human-readable help string describing the operation, its
|
|
94
|
+
* parameters, and the expected responses.
|
|
95
|
+
*/
|
|
96
|
+
help(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Executes the HTTP request and returns the parsed response body.
|
|
99
|
+
*
|
|
100
|
+
* @throws When no HTTP method has been set.
|
|
101
|
+
* @throws When required parameters are missing.
|
|
102
|
+
* @throws When an unsupported HTTP method is used.
|
|
103
|
+
*/
|
|
104
|
+
send(): Promise<unknown>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates a factory function that constructs a {@link RouteBuilder} for a
|
|
108
|
+
* given route path, pre-configured with the server's host, port, and OpenAPI
|
|
109
|
+
* route catalog.
|
|
110
|
+
*
|
|
111
|
+
* @param port - The port the Counterfact server is listening on.
|
|
112
|
+
* @param host - The server hostname (default `"localhost"`).
|
|
113
|
+
* @param routeCatalog - Optional route catalog for parameter introspection.
|
|
114
|
+
* @returns A function `(routePath: string) => RouteBuilder`.
|
|
115
|
+
*/
|
|
116
|
+
export declare function createRouteFunction(port: number, host?: string, routeCatalog?: RouteCatalog): (routePath: string) => RouteBuilder;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { RawHttpClient } from "./raw-http-client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Immutable fluent builder for constructing and sending HTTP requests from the
|
|
4
|
+
* Counterfact REPL.
|
|
5
|
+
*
|
|
6
|
+
* Each builder method returns a **new** `RouteBuilder` instance with the
|
|
7
|
+
* updated field — the original is never mutated. When all required parameters
|
|
8
|
+
* are set, call {@link send} to execute the request.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Inside the REPL:
|
|
12
|
+
* route("/pets/{petId}").method("get").path({ petId: 1 }).send();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class RouteBuilder {
|
|
16
|
+
routePath;
|
|
17
|
+
_body;
|
|
18
|
+
_headerParams;
|
|
19
|
+
_host;
|
|
20
|
+
_method;
|
|
21
|
+
_routeCatalog;
|
|
22
|
+
_pathParams;
|
|
23
|
+
_port;
|
|
24
|
+
_queryParams;
|
|
25
|
+
_operation;
|
|
26
|
+
constructor(routePath, options) {
|
|
27
|
+
this.routePath = routePath;
|
|
28
|
+
this._method = options.method;
|
|
29
|
+
this._pathParams = options.pathParams ?? {};
|
|
30
|
+
this._queryParams = options.queryParams ?? {};
|
|
31
|
+
this._headerParams = options.headerParams ?? {};
|
|
32
|
+
this._body = options.body;
|
|
33
|
+
this._port = options.port;
|
|
34
|
+
this._host = options.host ?? "localhost";
|
|
35
|
+
this._routeCatalog = options.routeCatalog;
|
|
36
|
+
this._operation = this._resolveOperation();
|
|
37
|
+
}
|
|
38
|
+
_resolveOperation() {
|
|
39
|
+
if (!this._routeCatalog || !this._method)
|
|
40
|
+
return undefined;
|
|
41
|
+
return this._routeCatalog.getOperation(this.routePath, this._method);
|
|
42
|
+
}
|
|
43
|
+
clone(overrides) {
|
|
44
|
+
return new RouteBuilder(this.routePath, {
|
|
45
|
+
body: "body" in overrides ? overrides.body : this._body,
|
|
46
|
+
headerParams: overrides.headerParams ?? this._headerParams,
|
|
47
|
+
host: this._host,
|
|
48
|
+
method: overrides.method ?? this._method,
|
|
49
|
+
pathParams: overrides.pathParams ?? this._pathParams,
|
|
50
|
+
port: this._port,
|
|
51
|
+
queryParams: overrides.queryParams ?? this._queryParams,
|
|
52
|
+
routeCatalog: this._routeCatalog,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a new builder with the HTTP method set.
|
|
57
|
+
*
|
|
58
|
+
* @param method - HTTP method name (case-insensitive, e.g. `"get"`, `"POST"`).
|
|
59
|
+
*/
|
|
60
|
+
method(method) {
|
|
61
|
+
return this.clone({ method: method.toUpperCase() });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns a new builder with additional path parameters merged in.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Key/value map of path variable names to values.
|
|
67
|
+
*/
|
|
68
|
+
path(params) {
|
|
69
|
+
return this.clone({ pathParams: { ...this._pathParams, ...params } });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns a new builder with additional query parameters merged in.
|
|
73
|
+
*
|
|
74
|
+
* @param params - Key/value map of query parameter names to values.
|
|
75
|
+
*/
|
|
76
|
+
query(params) {
|
|
77
|
+
return this.clone({ queryParams: { ...this._queryParams, ...params } });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns a new builder with additional request headers merged in.
|
|
81
|
+
*
|
|
82
|
+
* @param params - Key/value map of header names to values.
|
|
83
|
+
*/
|
|
84
|
+
headers(params) {
|
|
85
|
+
return this.clone({ headerParams: { ...this._headerParams, ...params } });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns a new builder with the request body set.
|
|
89
|
+
*
|
|
90
|
+
* @param body - The request body (will be serialised to JSON or sent as-is).
|
|
91
|
+
*/
|
|
92
|
+
body(body) {
|
|
93
|
+
return this.clone({ body });
|
|
94
|
+
}
|
|
95
|
+
getOperation() {
|
|
96
|
+
return this._operation;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns `true` when a method is set and no required parameters are
|
|
100
|
+
* missing.
|
|
101
|
+
*/
|
|
102
|
+
ready() {
|
|
103
|
+
if (!this._method)
|
|
104
|
+
return false;
|
|
105
|
+
return this.missing() === undefined;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns a {@link MissingParams} object describing all required parameters
|
|
109
|
+
* that have not yet been set, or `undefined` when nothing is missing (or
|
|
110
|
+
* when the operation has no parameters).
|
|
111
|
+
*/
|
|
112
|
+
missing() {
|
|
113
|
+
const operation = this.getOperation();
|
|
114
|
+
if (!operation?.parameters)
|
|
115
|
+
return undefined;
|
|
116
|
+
const missingParams = {};
|
|
117
|
+
for (const param of operation.parameters) {
|
|
118
|
+
if (!param.required)
|
|
119
|
+
continue;
|
|
120
|
+
const paramType = param.type ?? param.schema?.type ?? "string";
|
|
121
|
+
const paramInfo = {
|
|
122
|
+
description: param.description,
|
|
123
|
+
name: param.name,
|
|
124
|
+
type: paramType,
|
|
125
|
+
};
|
|
126
|
+
if (param.in === "path" && !(param.name in this._pathParams)) {
|
|
127
|
+
missingParams.path = [...(missingParams.path ?? []), paramInfo];
|
|
128
|
+
}
|
|
129
|
+
else if (param.in === "query" && !(param.name in this._queryParams)) {
|
|
130
|
+
missingParams.query = [...(missingParams.query ?? []), paramInfo];
|
|
131
|
+
}
|
|
132
|
+
else if (param.in === "header" && !(param.name in this._headerParams)) {
|
|
133
|
+
missingParams.header = [...(missingParams.header ?? []), paramInfo];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (Object.keys(missingParams).length === 0)
|
|
137
|
+
return undefined;
|
|
138
|
+
return missingParams;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns a human-readable help string describing the operation, its
|
|
142
|
+
* parameters, and the expected responses.
|
|
143
|
+
*/
|
|
144
|
+
help() {
|
|
145
|
+
const method = this._method ?? "[no method set]";
|
|
146
|
+
const operation = this.getOperation();
|
|
147
|
+
const lines = [];
|
|
148
|
+
lines.push(`${method} ${this.routePath}`);
|
|
149
|
+
if (operation?.summary) {
|
|
150
|
+
lines.push("");
|
|
151
|
+
lines.push("Summary:");
|
|
152
|
+
lines.push(` ${operation.summary}`);
|
|
153
|
+
}
|
|
154
|
+
if (operation?.description) {
|
|
155
|
+
lines.push("");
|
|
156
|
+
lines.push("Description:");
|
|
157
|
+
lines.push(` ${operation.description}`);
|
|
158
|
+
}
|
|
159
|
+
if (operation?.parameters && operation.parameters.length > 0) {
|
|
160
|
+
const pathParams = operation.parameters.filter((p) => p.in === "path");
|
|
161
|
+
const queryParams = operation.parameters.filter((p) => p.in === "query");
|
|
162
|
+
const headerParams = operation.parameters.filter((p) => p.in === "header");
|
|
163
|
+
if (pathParams.length > 0) {
|
|
164
|
+
lines.push("");
|
|
165
|
+
lines.push("Path Parameters:");
|
|
166
|
+
for (const p of pathParams) {
|
|
167
|
+
const paramType = p.type ?? p.schema?.type ?? "string";
|
|
168
|
+
const required = p.required ? "required" : "optional";
|
|
169
|
+
lines.push(` ${p.name} (${paramType}, ${required})`);
|
|
170
|
+
if (p.description)
|
|
171
|
+
lines.push(` Description: ${p.description}`);
|
|
172
|
+
if (p.enum)
|
|
173
|
+
lines.push(` Allowed values: ${p.enum.join(" | ")}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (queryParams.length > 0) {
|
|
177
|
+
lines.push("");
|
|
178
|
+
lines.push("Query Parameters:");
|
|
179
|
+
for (const p of queryParams) {
|
|
180
|
+
const paramType = p.type ?? p.schema?.type ?? "string";
|
|
181
|
+
const required = p.required ? "required" : "optional";
|
|
182
|
+
lines.push(` ${p.name} (${paramType}, ${required})`);
|
|
183
|
+
if (p.description)
|
|
184
|
+
lines.push(` Description: ${p.description}`);
|
|
185
|
+
const enumValues = p.enum ?? p.schema?.enum;
|
|
186
|
+
if (enumValues)
|
|
187
|
+
lines.push(` Allowed values: ${enumValues.join(" | ")}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (headerParams.length > 0) {
|
|
191
|
+
lines.push("");
|
|
192
|
+
lines.push("Headers:");
|
|
193
|
+
for (const p of headerParams) {
|
|
194
|
+
const paramType = p.type ?? p.schema?.type ?? "string";
|
|
195
|
+
const required = p.required ? "required" : "optional";
|
|
196
|
+
lines.push(` ${p.name} (${paramType}, ${required})`);
|
|
197
|
+
if (p.description)
|
|
198
|
+
lines.push(` Description: ${p.description}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (operation?.responses) {
|
|
203
|
+
lines.push("");
|
|
204
|
+
lines.push("Responses:");
|
|
205
|
+
for (const [status, response] of Object.entries(operation.responses)) {
|
|
206
|
+
lines.push(` ${status}`);
|
|
207
|
+
if (response.description) {
|
|
208
|
+
lines.push(` Description: ${response.description}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return lines.join("\n");
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Executes the HTTP request and returns the parsed response body.
|
|
216
|
+
*
|
|
217
|
+
* @throws When no HTTP method has been set.
|
|
218
|
+
* @throws When required parameters are missing.
|
|
219
|
+
* @throws When an unsupported HTTP method is used.
|
|
220
|
+
*/
|
|
221
|
+
async send() {
|
|
222
|
+
if (!this._method) {
|
|
223
|
+
throw new Error('No HTTP method set. Use .method("get") to set the method.');
|
|
224
|
+
}
|
|
225
|
+
const missing = this.missing();
|
|
226
|
+
if (missing) {
|
|
227
|
+
const lines = [
|
|
228
|
+
"Cannot execute request.",
|
|
229
|
+
"",
|
|
230
|
+
"Missing required parameters:",
|
|
231
|
+
];
|
|
232
|
+
if (missing.path) {
|
|
233
|
+
lines.push(" path:");
|
|
234
|
+
for (const p of missing.path) {
|
|
235
|
+
lines.push(` - ${p.name} (${p.type ?? "string"})`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (missing.query) {
|
|
239
|
+
lines.push(" query:");
|
|
240
|
+
for (const p of missing.query) {
|
|
241
|
+
lines.push(` - ${p.name} (${p.type ?? "string"})`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (missing.header) {
|
|
245
|
+
lines.push(" header:");
|
|
246
|
+
for (const p of missing.header) {
|
|
247
|
+
lines.push(` - ${p.name} (${p.type ?? "string"})`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
throw new Error(lines.join("\n"));
|
|
251
|
+
}
|
|
252
|
+
// Build URL with path parameters substituted
|
|
253
|
+
let url = this.routePath;
|
|
254
|
+
for (const [key, value] of Object.entries(this._pathParams)) {
|
|
255
|
+
url = url.replaceAll(`{${key}}`, String(value));
|
|
256
|
+
}
|
|
257
|
+
// Append query string
|
|
258
|
+
const queryEntries = Object.entries(this._queryParams);
|
|
259
|
+
if (queryEntries.length > 0) {
|
|
260
|
+
const qs = new URLSearchParams(queryEntries.map(([k, v]) => [k, String(v)])).toString();
|
|
261
|
+
url = `${url}?${qs}`;
|
|
262
|
+
}
|
|
263
|
+
const client = new RawHttpClient(this._host, this._port);
|
|
264
|
+
const headers = Object.fromEntries(Object.entries(this._headerParams).map(([k, v]) => [k, String(v)]));
|
|
265
|
+
const method = this._method.toLowerCase();
|
|
266
|
+
switch (method) {
|
|
267
|
+
case "get":
|
|
268
|
+
return client.get(url, headers);
|
|
269
|
+
case "head":
|
|
270
|
+
return client.head(url, headers);
|
|
271
|
+
case "delete":
|
|
272
|
+
return client.delete(url, headers);
|
|
273
|
+
case "options":
|
|
274
|
+
return client.options(url, headers);
|
|
275
|
+
case "trace":
|
|
276
|
+
return client.trace(url, headers);
|
|
277
|
+
case "post":
|
|
278
|
+
return client.post(url, this._body, headers);
|
|
279
|
+
case "put":
|
|
280
|
+
return client.put(url, this._body, headers);
|
|
281
|
+
case "patch":
|
|
282
|
+
return client.patch(url, this._body, headers);
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Unsupported HTTP method: ${this._method}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
288
|
+
const method = this._method ?? "[no method set]";
|
|
289
|
+
const operation = this.getOperation();
|
|
290
|
+
const lines = [];
|
|
291
|
+
lines.push(`${method} ${this.routePath}`);
|
|
292
|
+
if (operation?.parameters) {
|
|
293
|
+
const pathParams = operation.parameters.filter((p) => p.in === "path");
|
|
294
|
+
const queryParams = operation.parameters.filter((p) => p.in === "query");
|
|
295
|
+
if (pathParams.length > 0) {
|
|
296
|
+
lines.push("");
|
|
297
|
+
lines.push("Path:");
|
|
298
|
+
for (const p of pathParams) {
|
|
299
|
+
const value = this._pathParams[p.name];
|
|
300
|
+
lines.push(` ${p.name}: ${value !== undefined ? String(value) : "[missing]"}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (queryParams.length > 0) {
|
|
304
|
+
lines.push("");
|
|
305
|
+
lines.push("Query:");
|
|
306
|
+
for (const p of queryParams) {
|
|
307
|
+
const value = this._queryParams[p.name];
|
|
308
|
+
const label = p.required ? "[missing]" : "[optional]";
|
|
309
|
+
lines.push(` ${p.name}: ${value !== undefined ? String(value) : label}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
lines.push("");
|
|
314
|
+
lines.push(`Ready: ${this.ready()}`);
|
|
315
|
+
return lines.join("\n");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Creates a factory function that constructs a {@link RouteBuilder} for a
|
|
320
|
+
* given route path, pre-configured with the server's host, port, and OpenAPI
|
|
321
|
+
* route catalog.
|
|
322
|
+
*
|
|
323
|
+
* @param port - The port the Counterfact server is listening on.
|
|
324
|
+
* @param host - The server hostname (default `"localhost"`).
|
|
325
|
+
* @param routeCatalog - Optional route catalog for parameter introspection.
|
|
326
|
+
* @returns A function `(routePath: string) => RouteBuilder`.
|
|
327
|
+
*/
|
|
328
|
+
export function createRouteFunction(port, host, routeCatalog) {
|
|
329
|
+
return (routePath) => new RouteBuilder(routePath, { host, port, routeCatalog });
|
|
330
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Parameter metadata consumed by the request builder. */
|
|
2
|
+
export interface RouteParameter {
|
|
3
|
+
description?: string;
|
|
4
|
+
enum?: readonly string[];
|
|
5
|
+
in: "body" | "cookie" | "formData" | "header" | "path" | "query";
|
|
6
|
+
name: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
schema?: {
|
|
9
|
+
enum?: readonly string[];
|
|
10
|
+
type?: string;
|
|
11
|
+
};
|
|
12
|
+
type?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Operation metadata consumed by request help and validation. */
|
|
15
|
+
export interface RouteOperation {
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters?: readonly RouteParameter[];
|
|
18
|
+
responses?: Readonly<Record<string, {
|
|
19
|
+
description?: string;
|
|
20
|
+
}>>;
|
|
21
|
+
summary?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The small route-discovery contract used by {@link RouteBuilder} and the
|
|
25
|
+
* Counterfact REPL.
|
|
26
|
+
*/
|
|
27
|
+
export interface RouteCatalog {
|
|
28
|
+
getOperation(routePath: string, method: string): RouteOperation | undefined;
|
|
29
|
+
listPaths(): readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** The only OpenAPI document shape needed to create a route catalog. */
|
|
32
|
+
export interface OpenApiRouteDocument {
|
|
33
|
+
readonly paths: Readonly<Record<string, object>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Adapts an OpenAPI-like document to the client package's narrow route
|
|
37
|
+
* catalog. The document is retained by reference so live OpenAPI reloads are
|
|
38
|
+
* visible to subsequent lookups.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createOpenApiRouteCatalog(document: OpenApiRouteDocument): RouteCatalog;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts an OpenAPI-like document to the client package's narrow route
|
|
3
|
+
* catalog. The document is retained by reference so live OpenAPI reloads are
|
|
4
|
+
* visible to subsequent lookups.
|
|
5
|
+
*/
|
|
6
|
+
export function createOpenApiRouteCatalog(document) {
|
|
7
|
+
return {
|
|
8
|
+
getOperation(routePath, method) {
|
|
9
|
+
const normalizedPath = routePath.toLowerCase();
|
|
10
|
+
const matchingPath = Object.keys(document.paths).find((path) => path.toLowerCase() === normalizedPath);
|
|
11
|
+
if (matchingPath === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const pathItem = document.paths[matchingPath];
|
|
15
|
+
return pathItem?.[method.toLowerCase()];
|
|
16
|
+
},
|
|
17
|
+
listPaths() {
|
|
18
|
+
return Object.keys(document.paths);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createOpenApiRouteCatalog,
|
|
5
|
+
createRouteFunction,
|
|
6
|
+
} from "@counterfact/client";
|
|
7
|
+
|
|
8
|
+
const server = http.createServer((request, response) => {
|
|
9
|
+
response.setHeader("content-type", "application/json");
|
|
10
|
+
response.end(JSON.stringify({ path: request.url }));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const address = server.address();
|
|
17
|
+
if (address === null || typeof address === "string") {
|
|
18
|
+
throw new Error("Expected the HTTP server to use a TCP port");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const catalog = createOpenApiRouteCatalog({
|
|
22
|
+
paths: {
|
|
23
|
+
"/pets/{petId}": {
|
|
24
|
+
get: {
|
|
25
|
+
parameters: [
|
|
26
|
+
{
|
|
27
|
+
in: "path",
|
|
28
|
+
name: "petId",
|
|
29
|
+
required: true,
|
|
30
|
+
type: "integer",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
responses: { 200: { description: "A pet" } },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const route = createRouteFunction(address.port, "127.0.0.1", catalog);
|
|
39
|
+
const pet = route("/pets/{petId}").method("get").path({ petId: 42 });
|
|
40
|
+
|
|
41
|
+
await pet.send();
|
|
42
|
+
} finally {
|
|
43
|
+
await new Promise((resolve, reject) => {
|
|
44
|
+
server.close((error) => (error ? reject(error) : resolve()));
|
|
45
|
+
});
|
|
46
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@counterfact/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build and send reusable OpenAPI-aware HTTP requests without starting Counterfact.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"examples",
|
|
17
|
+
"README.md",
|
|
18
|
+
"License.md"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"author": "Patrick McElhaney <pmcelhaney@gmail.com>",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/counterfact/api-simulator.git",
|
|
26
|
+
"directory": "packages/client"
|
|
27
|
+
},
|
|
28
|
+
"bugs": "https://github.com/counterfact/api-simulator/issues",
|
|
29
|
+
"homepage": "https://counterfact.dev",
|
|
30
|
+
"funding": {
|
|
31
|
+
"type": "github",
|
|
32
|
+
"url": "https://github.com/sponsors/pmcelhaney"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"counterfact",
|
|
36
|
+
"openapi",
|
|
37
|
+
"api-client",
|
|
38
|
+
"http-client",
|
|
39
|
+
"typescript",
|
|
40
|
+
"testing"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "rimraf dist && tsc --build --force",
|
|
50
|
+
"prepack": "yarn build",
|
|
51
|
+
"test": "node --experimental-vm-modules ../../node_modules/jest-cli/bin/jest.js --config ../../jest.config.js packages/client/test",
|
|
52
|
+
"test:packed-consumer": "node test/package/client-consumer-smoke.mjs"
|
|
53
|
+
}
|
|
54
|
+
}
|