@schmock/cli 2.4.0 → 2.5.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/dist/admin.d.ts +41 -0
- package/dist/args.d.ts +17 -0
- package/dist/bin.d.ts +0 -1
- package/dist/bin.js +492 -418
- package/dist/cli.d.ts +4 -73
- package/dist/cors.d.ts +30 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +492 -418
- package/dist/request.d.ts +38 -0
- package/dist/seed-manifest.d.ts +15 -0
- package/dist/server.d.ts +14 -0
- package/dist/types.d.ts +28 -0
- package/dist/watch.d.ts +46 -0
- package/package.json +5 -5
- package/dist/bin.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type * as Schmock from "@schmock/core";
|
|
2
|
+
import type { HeaderSource } from "./cors.js";
|
|
3
|
+
import type { CliOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Requests retained for `GET /schmock-admin/history` when
|
|
6
|
+
* `--admin-history-limit` is not given. Core's own `maxHistorySize` defaults
|
|
7
|
+
* to unbounded, which a server left running all day cannot afford.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_ADMIN_HISTORY_LIMIT = 500;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a request targets the admin surface. Kept as one predicate because
|
|
12
|
+
* two sites depend on the same answer: the CORS decisions (the preflight
|
|
13
|
+
* short-circuit and the extra headers, which must *not* apply to admin paths)
|
|
14
|
+
* and admin dispatch itself.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAdminPath(admin: boolean, path: string): boolean;
|
|
17
|
+
export interface AdminRequest {
|
|
18
|
+
/** The raw request, for the `Origin` check and the presented token. */
|
|
19
|
+
readonly req: HeaderSource;
|
|
20
|
+
readonly method: Schmock.HttpMethod;
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly mock: Schmock.CallableMockInstance;
|
|
23
|
+
/** The token every admin request must present; see `resolveAdminToken`. */
|
|
24
|
+
readonly adminToken: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Answer a request on the admin surface ({@link isAdminPath}): a refusal
|
|
28
|
+
* unless it presents the admin token without an `Origin`, otherwise the
|
|
29
|
+
* endpoint's answer. Throws only when the mock's routes or state cannot be
|
|
30
|
+
* serialized.
|
|
31
|
+
*/
|
|
32
|
+
export declare function answerAdminRequest(request: AdminRequest): Schmock.Response;
|
|
33
|
+
export declare function isUsableAdminToken(value: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Settle the admin token once, at the outermost entry point, so every later
|
|
36
|
+
* consumer (listen, reload, the printed banner) sees the same value.
|
|
37
|
+
*
|
|
38
|
+
* @throws SchmockError `INVALID_CONFIG` for an empty token or one containing
|
|
39
|
+
* whitespace
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveAdminToken(options: CliOptions): string | undefined;
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CliOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loopback binds are `127.0.0.0/8` (also IPv4-mapped, `::ffff:127.x.x.x`),
|
|
4
|
+
* `::1` and `localhost`; everything else is reachable off-box.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isLoopbackHost(hostname: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Parse `schmock` command-line arguments into {@link CliOptions}.
|
|
9
|
+
*
|
|
10
|
+
* @throws SchmockError `INVALID_CONFIG` for a flag value the CLI refuses, a
|
|
11
|
+
* second positional argument, or `--admin-token` without `--admin`. An
|
|
12
|
+
* unknown flag throws Node's own `parseArgs` error.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseCliArgs(args: string[]): CliOptions & {
|
|
15
|
+
help: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const USAGE = "Usage: schmock <spec> [options]\n schmock --spec <path> [options]\n\nOptions:\n --spec <path> OpenAPI/Swagger spec file (or pass as first argument)\n --port <number> Port to listen on (default: 3000)\n --hostname <host> Hostname to bind to (default: 127.0.0.1)\n --seed <path> JSON file with seed data\n --cors Enable CORS for mock responses (never for /schmock-admin/*)\n --debug Enable debug logging\n --errors Enable request body validation against spec\n --watch Watch spec file and hot-reload on changes\n --admin Enable /schmock-admin/* introspection endpoints\n --admin-token <token>\n Bearer token required by /schmock-admin/*. Generated and\n printed to stderr when --admin is set without it.\n --admin-history-limit <n>\n Requests retained for /schmock-admin/history (default: 500).\n Without --admin no history is retained at all.\n --strict Validate the spec against the OpenAPI schema at startup\n --refs-external Resolve $refs to files outside the spec document\n --refs-allow-http <hosts>\n Also resolve http(s) $refs, limited to this comma-separated\n host list (empty list = any public host). Requires\n --refs-external.\n --seed-random <n> Seed for deterministic random generation\n -h, --help Show this help message\n";
|
package/dist/bin.d.ts
CHANGED