@wasit-dev/cli 0.8.0-beta.1 → 0.8.0-beta.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.
- package/README.md +46 -11
- package/dist/exit.d.ts +42 -0
- package/dist/exit.js +51 -0
- package/dist/index.js +163 -90
- package/dist/init-command.d.ts +98 -0
- package/dist/init-command.js +850 -0
- package/dist/init-keys.d.ts +110 -0
- package/dist/init-keys.js +539 -0
- package/dist/run.d.ts +26 -5
- package/dist/run.js +565 -153
- package/dist/service.d.ts +7 -2
- package/dist/service.js +7 -2
- package/dist/style.d.ts +2 -1
- package/dist/style.js +12 -2
- package/dist/test-live.d.ts +26 -0
- package/dist/test-live.js +81 -0
- package/dist/wallet-command.js +18 -9
- package/package.json +2 -2
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wasit init`: a `wasit.config.json` for one paid route of a service its
|
|
3
|
+
* operator runs (spec C; W3-2 slices 2 and 3).
|
|
4
|
+
*
|
|
5
|
+
* Every answer is a flag, so the same command works in a script, in
|
|
6
|
+
* PowerShell and in cmd.exe: no answer needs shell quoting (a body comes from
|
|
7
|
+
* a file). The file is written by core's config writer, which takes only data
|
|
8
|
+
* that is certain and checks the result with the validator `wasit run` reads
|
|
9
|
+
* the file with (Najmi, 2026-11-15). What the writer is not given, this
|
|
10
|
+
* command fills from a fixed fallback table (init-skeleton-plan.md section 6),
|
|
11
|
+
* and says so: after writing it prints what it read from the service, what was
|
|
12
|
+
* given, what was filled in by default, and what was NOT read.
|
|
13
|
+
*
|
|
14
|
+
* Reading the route (C2, slice 3) is the default: one unpaid request with the
|
|
15
|
+
* route's method and body (and the `WASIT_HEADER_*` headers `wasit run` would
|
|
16
|
+
* send), one redirect inside the origin at most, no payment, no signature, no
|
|
17
|
+
* key. Its 402 tells x402 from MPP and fills in the protocol, the network, the
|
|
18
|
+
* pin (receiving address and asset) and an MPP channel. A route that answers
|
|
19
|
+
* 200, 500 or 503, or nothing, is said in plain words and nothing is written;
|
|
20
|
+
* `--no-read` writes the route from the flags alone, as x402 (slice 2).
|
|
21
|
+
*
|
|
22
|
+
* The testnet key setup (C4, slice 5, `init-keys.ts`) comes last, for a route
|
|
23
|
+
* on Stellar testnet: with `--setup-keys`, or a yes at a terminal. It writes the
|
|
24
|
+
* key the route's payment checks read into `.env` (never into the config, and
|
|
25
|
+
* never printed) after checking that git will not commit `.env`.
|
|
26
|
+
*
|
|
27
|
+
* Nothing is sent and nothing is written without `--operated-by-me`: Wasit
|
|
28
|
+
* tests only services their operator runs. Every flag is checked before the
|
|
29
|
+
* route is asked anything. An existing config is added to, never overwritten
|
|
30
|
+
* silently; `--force` replaces it. A route it already has exactly as given, in
|
|
31
|
+
* the same environment, is left as it is, byte for byte, and the run goes on
|
|
32
|
+
* (to the key setup): init can be run again on the same route. Mainnet is not written in this version, and
|
|
33
|
+
* nothing that could hold a secret is: an endpoint's headers are not written (a
|
|
34
|
+
* credential goes in `WASIT_HEADER_*`). What the service answered is data:
|
|
35
|
+
* printed through the sanitiser, never followed or run.
|
|
36
|
+
*
|
|
37
|
+
* `executeInit` does not call `process.exit` and does not read the process:
|
|
38
|
+
* the environment and the output are passed in, so it can be tested in-process.
|
|
39
|
+
*/
|
|
40
|
+
import { type KeySetupDeps } from "./init-keys.js";
|
|
41
|
+
export declare const DEFAULT_CONFIG_FILE = "wasit.config.json";
|
|
42
|
+
export interface InitCommandOptions {
|
|
43
|
+
readonly url?: string;
|
|
44
|
+
readonly operatedByMe: boolean;
|
|
45
|
+
readonly name?: string;
|
|
46
|
+
readonly method?: string;
|
|
47
|
+
readonly bodyFile?: string;
|
|
48
|
+
/** Chooses among the ways the route offers to pay; without reading, the network written. */
|
|
49
|
+
readonly network?: string;
|
|
50
|
+
/** Chooses among the ways the route offers to pay. */
|
|
51
|
+
readonly protocol?: string;
|
|
52
|
+
readonly env?: string;
|
|
53
|
+
readonly start?: string;
|
|
54
|
+
readonly readyUrl?: string;
|
|
55
|
+
readonly readyTimeout?: string;
|
|
56
|
+
/** `Name: value`, repeatable: the headers of the request the route must refuse (X402-11). */
|
|
57
|
+
readonly rejectHeader: readonly string[];
|
|
58
|
+
readonly rejectBodyFile?: string;
|
|
59
|
+
readonly rejectNote?: string;
|
|
60
|
+
readonly config: string;
|
|
61
|
+
readonly force: boolean;
|
|
62
|
+
/** Read the route's 402 (the default); false is `--no-read`: no request, x402 from the flags. */
|
|
63
|
+
readonly read: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The testnet key setup (C4): true is `--setup-keys`, false `--no-setup-keys`.
|
|
66
|
+
* Undefined: asked at a terminal, else not done.
|
|
67
|
+
*/
|
|
68
|
+
readonly setupKeys?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface InitContext {
|
|
71
|
+
/** The `WASIT_HEADER_*` variables the read sends, and the values kept out of every printed line. */
|
|
72
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
73
|
+
/** One line at a time, the line break added by the caller. */
|
|
74
|
+
readonly stdout: (line: string) => void;
|
|
75
|
+
readonly stderr: (line: string) => void;
|
|
76
|
+
/** Where relative paths are read from and the config is written. Default: the working directory. */
|
|
77
|
+
readonly cwd?: string;
|
|
78
|
+
/** Tests only: how long the read waits for the route. Index never sets it. */
|
|
79
|
+
readonly readTimeoutMs?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Asks one question and returns the answer. Given only when stdin and stdout
|
|
82
|
+
* are terminals (C1): without it, init asks nothing and names the flags that
|
|
83
|
+
* are missing (C5). Rejects when the input ends.
|
|
84
|
+
*/
|
|
85
|
+
readonly ask?: (question: string) => Promise<string>;
|
|
86
|
+
/** The outside world of the key setup (git, Friendbot, Horizon, the key generator). Needed when the key setup runs. */
|
|
87
|
+
readonly keys?: KeySetupDeps;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Runs `wasit init`. Returns the exit code: 0 the file has the route (written
|
|
91
|
+
* now, or already there as given and left as it is); 2 nothing was written (a
|
|
92
|
+
* flag is missing or wrong, the service is not yours, the route is not a
|
|
93
|
+
* paywall init can read, or the writer refused the data). The key setup runs
|
|
94
|
+
* after the file is written and never changes the exit code: what
|
|
95
|
+
* it could not do is in its status table, with the command that finishes it
|
|
96
|
+
* (Najmi, 2026-11-27).
|
|
97
|
+
*/
|
|
98
|
+
export declare function executeInit(given: InitCommandOptions, context: InitContext): Promise<number>;
|