x402check 0.2.0 → 0.3.1
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 +47 -0
- package/dist/cli.mjs +2353 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -10,6 +10,29 @@ Validate [x402](https://www.x402.org/) payment configurations. Works in Node, br
|
|
|
10
10
|
npm i x402check
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## CLI
|
|
14
|
+
|
|
15
|
+
Validate configs from the command line — no code required.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npx x402check '{"x402Version":2,"accepts":[...]}'
|
|
19
|
+
npx x402check config.json
|
|
20
|
+
npx x402check https://api.example.com/resource
|
|
21
|
+
echo '...' | npx x402check
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Flags:
|
|
25
|
+
|
|
26
|
+
| Flag | Description |
|
|
27
|
+
|------|-------------|
|
|
28
|
+
| `--strict` | Promote all warnings to errors |
|
|
29
|
+
| `--json` | Output raw JSON (for piping) |
|
|
30
|
+
| `--quiet` | Suppress output, exit code only |
|
|
31
|
+
|
|
32
|
+
Exit codes: `0` valid, `1` invalid, `2` input error.
|
|
33
|
+
|
|
34
|
+
Install globally with `npm i -g x402check` to use `x402check` directly.
|
|
35
|
+
|
|
13
36
|
## Quick start
|
|
14
37
|
|
|
15
38
|
```js
|
|
@@ -35,6 +58,30 @@ result.normalized // canonical v2 config
|
|
|
35
58
|
|
|
36
59
|
## API
|
|
37
60
|
|
|
61
|
+
### `check(response, options?)`
|
|
62
|
+
|
|
63
|
+
All-in-one: extracts config from an HTTP 402 response, validates it, and enriches with registry data (network names, asset symbols, decimals).
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { check } from 'x402check'
|
|
67
|
+
|
|
68
|
+
const res = await fetch(url)
|
|
69
|
+
const result = check({
|
|
70
|
+
body: await res.json(),
|
|
71
|
+
headers: res.headers
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
result.extracted // true | false
|
|
75
|
+
result.source // 'body' | 'header' | null
|
|
76
|
+
result.valid // true | false
|
|
77
|
+
result.errors // ValidationIssue[]
|
|
78
|
+
result.warnings // ValidationIssue[]
|
|
79
|
+
result.summary // AcceptSummary[] — display-ready payment options
|
|
80
|
+
result.normalized // canonical v2 config
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Each `summary` entry includes `networkName`, `assetSymbol`, `assetDecimals`, and other registry-resolved fields.
|
|
84
|
+
|
|
38
85
|
### `validate(input, options?)`
|
|
39
86
|
|
|
40
87
|
Validates a config object or JSON string. Returns errors, warnings, and a normalized v2 config.
|