@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
package/dist/service.d.ts
CHANGED
|
@@ -17,8 +17,13 @@
|
|
|
17
17
|
* SIGINT, SIGTERM and SIGHUP, and, as a last synchronous resort, when the Node
|
|
18
18
|
* process exits. A SIGKILL of Wasit itself cannot be caught.
|
|
19
19
|
*
|
|
20
|
-
* Windows: the group kill is `taskkill /pid <pid> /T /F`.
|
|
21
|
-
*
|
|
20
|
+
* Windows: the group kill is `taskkill /pid <pid> /T /F`. It was run once on
|
|
21
|
+
* Windows 11 (26H2, Node 24, PowerShell, 2026-11-29): `wasit run --read-only
|
|
22
|
+
* --start` against a service started with `npm start` left no listener and no
|
|
23
|
+
* node process, after a run that ended normally and after Ctrl+C (with `node` run
|
|
24
|
+
* directly: `npx.cmd` is a batch file, and `cmd.exe` asks "Terminate batch job"
|
|
25
|
+
* itself). Not run: the payment tier, other Windows versions and other ways
|
|
26
|
+
* a run can end (a failing run, SIGTERM, SIGHUP).
|
|
22
27
|
*/
|
|
23
28
|
/**
|
|
24
29
|
* The OS user a service runs as when it must not share a user with the payer
|
package/dist/service.js
CHANGED
|
@@ -17,8 +17,13 @@
|
|
|
17
17
|
* SIGINT, SIGTERM and SIGHUP, and, as a last synchronous resort, when the Node
|
|
18
18
|
* process exits. A SIGKILL of Wasit itself cannot be caught.
|
|
19
19
|
*
|
|
20
|
-
* Windows: the group kill is `taskkill /pid <pid> /T /F`.
|
|
21
|
-
*
|
|
20
|
+
* Windows: the group kill is `taskkill /pid <pid> /T /F`. It was run once on
|
|
21
|
+
* Windows 11 (26H2, Node 24, PowerShell, 2026-11-29): `wasit run --read-only
|
|
22
|
+
* --start` against a service started with `npm start` left no listener and no
|
|
23
|
+
* node process, after a run that ended normally and after Ctrl+C (with `node` run
|
|
24
|
+
* directly: `npx.cmd` is a batch file, and `cmd.exe` asks "Terminate batch job"
|
|
25
|
+
* itself). Not run: the payment tier, other Windows versions and other ways
|
|
26
|
+
* a run can end (a failing run, SIGTERM, SIGHUP).
|
|
22
27
|
*/
|
|
23
28
|
import { spawn, spawnSync } from "node:child_process";
|
|
24
29
|
import { existsSync, realpathSync } from "node:fs";
|
package/dist/style.d.ts
CHANGED
|
@@ -95,7 +95,8 @@ export declare function spread(left: string, right: string, width: number): stri
|
|
|
95
95
|
export declare function truncate(text: string, max: number): string;
|
|
96
96
|
/**
|
|
97
97
|
* Plain text wrapped to `width` columns, every line after `indent`. A word
|
|
98
|
-
* longer than a line (a URL, a hash) is kept whole and runs over.
|
|
98
|
+
* longer than a line (a URL, a hash) is kept whole and runs over. No line
|
|
99
|
+
* starts with a workflow command (`breakCommandStart`).
|
|
99
100
|
*/
|
|
100
101
|
export declare function wrap(text: string, width: number, indent: string): string[];
|
|
101
102
|
/**
|
package/dist/style.js
CHANGED
|
@@ -160,9 +160,19 @@ export function truncate(text, max) {
|
|
|
160
160
|
return "…".slice(0, Math.max(0, max));
|
|
161
161
|
return `${chars.slice(0, max - 1).join("")}…`;
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* A wrapped line that would start with a workflow command once the runner trims
|
|
165
|
+
* its indent (`::name::`, `##[name]`), broken the way the sanitiser breaks one
|
|
166
|
+
* at the start of a text. Wrapping makes new line starts out of words in the
|
|
167
|
+
* middle of a text, after the sanitiser ran, so each one is checked here.
|
|
168
|
+
*/
|
|
169
|
+
function breakCommandStart(line) {
|
|
170
|
+
return line.replace(/^(::|##\[)/, (command) => (command === "::" ? ": :" : "# #["));
|
|
171
|
+
}
|
|
163
172
|
/**
|
|
164
173
|
* Plain text wrapped to `width` columns, every line after `indent`. A word
|
|
165
|
-
* longer than a line (a URL, a hash) is kept whole and runs over.
|
|
174
|
+
* longer than a line (a URL, a hash) is kept whole and runs over. No line
|
|
175
|
+
* starts with a workflow command (`breakCommandStart`).
|
|
166
176
|
*/
|
|
167
177
|
export function wrap(text, width, indent) {
|
|
168
178
|
const room = Math.max(20, width - [...indent].length);
|
|
@@ -180,7 +190,7 @@ export function wrap(text, width, indent) {
|
|
|
180
190
|
}
|
|
181
191
|
if (current !== "")
|
|
182
192
|
lines.push(current);
|
|
183
|
-
return lines.map((line) => `${indent}${line}`);
|
|
193
|
+
return lines.map((line) => `${indent}${breakCommandStart(line)}`);
|
|
184
194
|
}
|
|
185
195
|
/**
|
|
186
196
|
* The width lines are laid out to: one column less than the terminal's (a line
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wasit test` for a person at a terminal: the same checks, notes and exit code
|
|
3
|
+
* as the plain output, drawn live (a RUNNING line with a timer while a check is
|
|
4
|
+
* in flight, each result as it arrives, the counts and the duration at the end).
|
|
5
|
+
*
|
|
6
|
+
* Its own module so that a test can drive it with a stream, an environment and
|
|
7
|
+
* stand-in checks, and hold it to what the plain output promises: every text a
|
|
8
|
+
* service chose is sanitised, and no secret of the environment is printed.
|
|
9
|
+
*/
|
|
10
|
+
import { runX402PaymentChecks, runX402ReadChecks } from "@wasit-dev/core";
|
|
11
|
+
import { type LiveStream } from "./live.js";
|
|
12
|
+
export interface LiveTestShape {
|
|
13
|
+
method?: string;
|
|
14
|
+
body?: string;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export interface LiveTestDeps {
|
|
18
|
+
/** Where the output goes: `process.stdout` in the CLI. */
|
|
19
|
+
readonly stream: LiveStream;
|
|
20
|
+
/** The environment the payer key and the secrets are read from: `process.env` in the CLI. */
|
|
21
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
22
|
+
/** The checks, replaceable in tests. */
|
|
23
|
+
readonly readChecks?: typeof runX402ReadChecks;
|
|
24
|
+
readonly paymentChecks?: typeof runX402PaymentChecks;
|
|
25
|
+
}
|
|
26
|
+
export declare function liveX402Test(opts: Record<string, unknown>, shape: LiveTestShape, deps: LiveTestDeps): Promise<number>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wasit test` for a person at a terminal: the same checks, notes and exit code
|
|
3
|
+
* as the plain output, drawn live (a RUNNING line with a timer while a check is
|
|
4
|
+
* in flight, each result as it arrives, the counts and the duration at the end).
|
|
5
|
+
*
|
|
6
|
+
* Its own module so that a test can drive it with a stream, an environment and
|
|
7
|
+
* stand-in checks, and hold it to what the plain output promises: every text a
|
|
8
|
+
* service chose is sanitised, and no secret of the environment is printed.
|
|
9
|
+
*/
|
|
10
|
+
import { X402_PAYMENT_CHECK_IDS, catalogueEntry, deniedEnvValues, endpointOutcome, networkClass, paymentChainFor, runX402PaymentChecks, runX402ReadChecks, sanitizeText, } from "@wasit-dev/core";
|
|
11
|
+
import { LiveReport } from "./live.js";
|
|
12
|
+
import { exitCodeFor, verdictNotes } from "./output.js";
|
|
13
|
+
import { colorDepth, liveEnabled } from "./style.js";
|
|
14
|
+
import { CLI_VERSION } from "./version.js";
|
|
15
|
+
export async function liveX402Test(opts, shape, deps) {
|
|
16
|
+
const { stream, env } = deps;
|
|
17
|
+
const readChecks = deps.readChecks ?? runX402ReadChecks;
|
|
18
|
+
const paymentChecks = deps.paymentChecks ?? runX402PaymentChecks;
|
|
19
|
+
const secrets = deniedEnvValues(env);
|
|
20
|
+
const live = new LiveReport({
|
|
21
|
+
stream,
|
|
22
|
+
live: liveEnabled(stream, env),
|
|
23
|
+
depth: colorDepth(env),
|
|
24
|
+
clean: (text) => sanitizeText(text, { redact: secrets }),
|
|
25
|
+
});
|
|
26
|
+
const target = opts["target"];
|
|
27
|
+
const network = opts["network"];
|
|
28
|
+
live.header(CLI_VERSION, "x402 conformance", [
|
|
29
|
+
["target", `${target}${shape.method !== undefined ? ` ${shape.method.toUpperCase()}` : ""}`],
|
|
30
|
+
["network", network],
|
|
31
|
+
]);
|
|
32
|
+
live.phase("challenge", [["no payment"]]);
|
|
33
|
+
live.running("X402-01..05", "Challenge checks");
|
|
34
|
+
const results = await readChecks({ target, ...shape, onResult: (result) => live.result(result) });
|
|
35
|
+
live.gap();
|
|
36
|
+
const keyEnv = paymentChainFor(network)?.payerKeyEnv ?? "STELLAR_PRIVATE_KEY";
|
|
37
|
+
const payerKey = opts["payerKey"] ?? env[keyEnv];
|
|
38
|
+
if (opts["readOnly"] === true) {
|
|
39
|
+
live.phase("payment", [["not run"]]);
|
|
40
|
+
live.note("--read-only set: the payment checks were not run.");
|
|
41
|
+
}
|
|
42
|
+
else if (!payerKey) {
|
|
43
|
+
live.phase("payment", [["not run"]]);
|
|
44
|
+
live.note(`No payer key: set ${keyEnv} in .env or pass --payer-key. The payment checks were not run.`);
|
|
45
|
+
}
|
|
46
|
+
else if (networkClass(network) !== "test") {
|
|
47
|
+
// Not a test network: the guard refuses the payment checks before anything
|
|
48
|
+
// is signed (the PREFLIGHT line says why), so no money moves.
|
|
49
|
+
live.phase("payment", [[network], ["not a test network: refused", "danger"]]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
live.phase("payment", [[network], ["testnet funds move", "warning"]]);
|
|
53
|
+
live.note(`When the target offers a ${network} option, X402-06 settles a real payment and X402-07..10 send ` +
|
|
54
|
+
"payments it must refuse.");
|
|
55
|
+
}
|
|
56
|
+
if (opts["readOnly"] !== true && payerKey) {
|
|
57
|
+
const order = X402_PAYMENT_CHECK_IDS;
|
|
58
|
+
const startAt = (index) => {
|
|
59
|
+
const id = order[index];
|
|
60
|
+
if (id !== undefined)
|
|
61
|
+
live.running(id, catalogueEntry(id)?.name ?? id);
|
|
62
|
+
};
|
|
63
|
+
startAt(0);
|
|
64
|
+
results.push(...(await paymentChecks({
|
|
65
|
+
target,
|
|
66
|
+
network,
|
|
67
|
+
payerSecretKey: payerKey,
|
|
68
|
+
...(opts["rpcUrl"] ? { rpcUrl: opts["rpcUrl"] } : {}),
|
|
69
|
+
...shape,
|
|
70
|
+
onResult: (result) => {
|
|
71
|
+
live.result(result);
|
|
72
|
+
const index = order.indexOf(result.id);
|
|
73
|
+
if (index >= 0)
|
|
74
|
+
startAt(index + 1);
|
|
75
|
+
},
|
|
76
|
+
onProgress: (line) => live.progress(line),
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
live.finish(results, endpointOutcome(results, "x402"), verdictNotes(results, "x402"));
|
|
80
|
+
return exitCodeFor(results, "x402");
|
|
81
|
+
}
|
package/dist/wallet-command.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { oraPromise } from "ora";
|
|
17
17
|
import { createUsdcTrustline, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, paymentChainFor, publicKeyFromSecret, sendUsdcFromDistributor, TESTNET_USDC_ISSUER, } from "@wasit-dev/core";
|
|
18
18
|
import { DEFAULT_SERVE_NETWORK, SERVE_NETWORKS } from "./serve.js";
|
|
19
|
+
import { finish } from "./exit.js";
|
|
19
20
|
/** Every role a key can be generated for. */
|
|
20
21
|
const ROLES = ["x402", "mpp-charge", "mpp-channel"];
|
|
21
22
|
/**
|
|
@@ -258,7 +259,8 @@ docs/guides/configuration.md) and has no on-chain balance of its own.`)
|
|
|
258
259
|
if (opts.network !== DEFAULT_SERVE_NETWORK) {
|
|
259
260
|
const role = opts.role === undefined ? "x402" : requireRole(opts.role, ACCOUNT_ROLES);
|
|
260
261
|
const network = requireNetwork(opts.network, role);
|
|
261
|
-
|
|
262
|
+
finish(await printPayerStatus(network, jsonMode));
|
|
263
|
+
return;
|
|
262
264
|
}
|
|
263
265
|
const roles = opts.role !== undefined ? [requireRole(opts.role, ACCOUNT_ROLES)] : ACCOUNT_ROLES;
|
|
264
266
|
const rows = [];
|
|
@@ -295,7 +297,8 @@ docs/guides/configuration.md) and has no on-chain balance of its own.`)
|
|
|
295
297
|
const exitCode = walletStatusExitCode(opts.role !== undefined, rows);
|
|
296
298
|
if (jsonMode) {
|
|
297
299
|
console.log(JSON.stringify(rows, null, 2));
|
|
298
|
-
|
|
300
|
+
finish(exitCode);
|
|
301
|
+
return;
|
|
299
302
|
}
|
|
300
303
|
for (const row of rows) {
|
|
301
304
|
if (!row.configured) {
|
|
@@ -309,7 +312,7 @@ docs/guides/configuration.md) and has no on-chain balance of its own.`)
|
|
|
309
312
|
}
|
|
310
313
|
printWalletStatus(row.role, row.publicKey, row.status);
|
|
311
314
|
}
|
|
312
|
-
|
|
315
|
+
finish(exitCode);
|
|
313
316
|
});
|
|
314
317
|
wallet
|
|
315
318
|
.command("create")
|
|
@@ -375,7 +378,8 @@ are recording, and never paste a pubnet key into these variables.`)
|
|
|
375
378
|
});
|
|
376
379
|
}
|
|
377
380
|
catch {
|
|
378
|
-
|
|
381
|
+
finish(1);
|
|
382
|
+
return;
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
385
|
});
|
|
@@ -425,7 +429,8 @@ prints where to get USDC for the configured x402 payer.`)
|
|
|
425
429
|
});
|
|
426
430
|
}
|
|
427
431
|
catch {
|
|
428
|
-
|
|
432
|
+
finish(1);
|
|
433
|
+
return;
|
|
429
434
|
}
|
|
430
435
|
return;
|
|
431
436
|
}
|
|
@@ -435,7 +440,8 @@ prints where to get USDC for the configured x402 payer.`)
|
|
|
435
440
|
}
|
|
436
441
|
catch (error) {
|
|
437
442
|
console.error(`Could not read the account: ${messageOf(error)}`);
|
|
438
|
-
|
|
443
|
+
finish(1);
|
|
444
|
+
return;
|
|
439
445
|
}
|
|
440
446
|
const xlmBalance = before.balances.find((balance) => balance.code === "XLM");
|
|
441
447
|
if (!before.exists || Number(xlmBalance?.balance ?? "0") < 2) {
|
|
@@ -447,7 +453,8 @@ prints where to get USDC for the configured x402 payer.`)
|
|
|
447
453
|
});
|
|
448
454
|
}
|
|
449
455
|
catch {
|
|
450
|
-
|
|
456
|
+
finish(1);
|
|
457
|
+
return;
|
|
451
458
|
}
|
|
452
459
|
}
|
|
453
460
|
try {
|
|
@@ -458,7 +465,8 @@ prints where to get USDC for the configured x402 payer.`)
|
|
|
458
465
|
});
|
|
459
466
|
}
|
|
460
467
|
catch {
|
|
461
|
-
|
|
468
|
+
finish(1);
|
|
469
|
+
return;
|
|
462
470
|
}
|
|
463
471
|
const distributorSecret = process.env.WASIT_USDC_DISTRIBUTOR_SECRET;
|
|
464
472
|
if (!distributorSecret) {
|
|
@@ -477,7 +485,8 @@ prints where to get USDC for the configured x402 payer.`)
|
|
|
477
485
|
});
|
|
478
486
|
}
|
|
479
487
|
catch {
|
|
480
|
-
|
|
488
|
+
finish(1);
|
|
489
|
+
return;
|
|
481
490
|
}
|
|
482
491
|
});
|
|
483
492
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wasit-dev/cli",
|
|
3
|
-
"version": "0.8.0-beta.
|
|
3
|
+
"version": "0.8.0-beta.3",
|
|
4
4
|
"description": "CLI for x402/MPP protocol-conformance testing on Stellar — verifies a service's payment flow settles on-chain per spec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typecheck": "tsc -p test/tsconfig.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wasit-dev/core": "^0.8.0-beta.
|
|
44
|
+
"@wasit-dev/core": "^0.8.0-beta.3",
|
|
45
45
|
"cfonts": "^3.3.1",
|
|
46
46
|
"commander": "^15.0.0",
|
|
47
47
|
"dotenv": "^17.4.2",
|