moltspay 0.5.1 → 0.5.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 CHANGED
@@ -461,6 +461,38 @@ moltspay transfer --to 0x... --amount 10 --secure
461
461
  moltspay chains
462
462
  ```
463
463
 
464
+ ### x402 CLI Examples (Cross-Platform)
465
+
466
+ The x402 command sends JSON payloads. Quote handling differs by shell:
467
+
468
+ **Linux / Mac (bash/zsh):**
469
+ ```bash
470
+ npx moltspay x402 https://example.com/api \
471
+ -X POST \
472
+ -d '{"prompt": "your text here"}' \
473
+ -v
474
+ ```
475
+
476
+ **Windows PowerShell:**
477
+ ```powershell
478
+ # Option 1: Use a JSON file (recommended)
479
+ echo '{"prompt": "your text here"}' > request.json
480
+ npx moltspay x402 https://example.com/api -X POST -d "@request.json" -v
481
+
482
+ # Option 2: Escape with backtick
483
+ npx moltspay x402 https://example.com/api -X POST -d "{`"prompt`": `"your text`"}" -v
484
+
485
+ # Option 3: Use cmd /c wrapper
486
+ cmd /c "npx moltspay x402 https://example.com/api -X POST -d ""{\""prompt\"": \""your text\""}"" -v"
487
+ ```
488
+
489
+ **Windows CMD:**
490
+ ```cmd
491
+ npx moltspay x402 https://example.com/api -X POST -d "{\"prompt\": \"your text\"}" -v
492
+ ```
493
+
494
+ **Cross-platform tip:** For complex JSON, save to a file and use `-d @filename.json` - works on all systems!
495
+
464
496
  ## Environment Variables
465
497
 
466
498
  ```bash
package/dist/cli.js CHANGED
@@ -1868,7 +1868,7 @@ program.command("spend").description("Spend USDC from Owner wallet (requires per
1868
1868
  console.log(JSON.stringify(result, null, 2));
1869
1869
  process.exit(result.success ? 0 : 1);
1870
1870
  });
1871
- program.command("x402").description("Make HTTP request with automatic x402 payment").argument("<url>", "URL to request").option("-X, --method <method>", "HTTP method", "GET").option("-d, --data <json>", "Request body (JSON)").option("-H, --header <header...>", "Additional headers (key:value)").option("-c, --chain <chain>", "Chain name", "base").option("--cdp", "Use CDP wallet").option("-o, --output <file>", "Save response to file").option("-v, --verbose", "Show payment details").action(async (url, options) => {
1871
+ program.command("x402").description("Make HTTP request with automatic x402 payment").argument("<url>", "URL to request").option("-X, --method <method>", "HTTP method", "GET").option("-d, --data <json>", "Request body (JSON)").option("-i, --image <path>", "Image file to include (reads file and sends as base64)").option("-H, --header <header...>", "Additional headers (key:value)").option("-c, --chain <chain>", "Chain name", "base").option("--cdp", "Use CDP wallet").option("-o, --output <file>", "Save response to file").option("-v, --verbose", "Show payment details").action(async (url, options) => {
1872
1872
  const { createX402Client: createX402Client2, isX402Available: isX402Available2 } = await Promise.resolve().then(() => (init_client(), client_exports));
1873
1873
  if (!isX402Available2()) {
1874
1874
  console.error("\u274C x402 packages not installed.");
@@ -1903,8 +1903,31 @@ program.command("x402").description("Make HTTP request with automatic x402 payme
1903
1903
  method: options.method.toUpperCase(),
1904
1904
  headers
1905
1905
  };
1906
- if (options.data && ["POST", "PUT", "PATCH"].includes(init.method)) {
1907
- init.body = options.data;
1906
+ let bodyData = {};
1907
+ if (options.data) {
1908
+ try {
1909
+ bodyData = JSON.parse(options.data);
1910
+ } catch {
1911
+ bodyData = { data: options.data };
1912
+ }
1913
+ }
1914
+ if (options.image) {
1915
+ const fs4 = await import("fs");
1916
+ const path4 = await import("path");
1917
+ const imagePath = path4.resolve(options.image);
1918
+ if (!fs4.existsSync(imagePath)) {
1919
+ console.error(`\u274C Image file not found: ${imagePath}`);
1920
+ process.exit(1);
1921
+ }
1922
+ const imageBuffer = fs4.readFileSync(imagePath);
1923
+ const imageBase64 = imageBuffer.toString("base64");
1924
+ if (options.verbose) {
1925
+ console.error(`\u{1F4F7} Image: ${imagePath} (${Math.round(imageBuffer.length / 1024)}KB)`);
1926
+ }
1927
+ bodyData.image_base64 = imageBase64;
1928
+ }
1929
+ if (["POST", "PUT", "PATCH"].includes(init.method) && Object.keys(bodyData).length > 0) {
1930
+ init.body = JSON.stringify(bodyData);
1908
1931
  }
1909
1932
  if (options.verbose) {
1910
1933
  console.error(`\u{1F4E4} ${init.method} ${url}`);