moltspay 0.5.1 → 0.5.2

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/cli.mjs CHANGED
@@ -1853,7 +1853,7 @@ program.command("spend").description("Spend USDC from Owner wallet (requires per
1853
1853
  console.log(JSON.stringify(result, null, 2));
1854
1854
  process.exit(result.success ? 0 : 1);
1855
1855
  });
1856
- 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) => {
1856
+ 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) => {
1857
1857
  const { createX402Client: createX402Client2, isX402Available: isX402Available2 } = await Promise.resolve().then(() => (init_client(), client_exports));
1858
1858
  if (!isX402Available2()) {
1859
1859
  console.error("\u274C x402 packages not installed.");
@@ -1888,8 +1888,31 @@ program.command("x402").description("Make HTTP request with automatic x402 payme
1888
1888
  method: options.method.toUpperCase(),
1889
1889
  headers
1890
1890
  };
1891
- if (options.data && ["POST", "PUT", "PATCH"].includes(init.method)) {
1892
- init.body = options.data;
1891
+ let bodyData = {};
1892
+ if (options.data) {
1893
+ try {
1894
+ bodyData = JSON.parse(options.data);
1895
+ } catch {
1896
+ bodyData = { data: options.data };
1897
+ }
1898
+ }
1899
+ if (options.image) {
1900
+ const fs4 = await import("fs");
1901
+ const path4 = await import("path");
1902
+ const imagePath = path4.resolve(options.image);
1903
+ if (!fs4.existsSync(imagePath)) {
1904
+ console.error(`\u274C Image file not found: ${imagePath}`);
1905
+ process.exit(1);
1906
+ }
1907
+ const imageBuffer = fs4.readFileSync(imagePath);
1908
+ const imageBase64 = imageBuffer.toString("base64");
1909
+ if (options.verbose) {
1910
+ console.error(`\u{1F4F7} Image: ${imagePath} (${Math.round(imageBuffer.length / 1024)}KB)`);
1911
+ }
1912
+ bodyData.image_base64 = imageBase64;
1913
+ }
1914
+ if (["POST", "PUT", "PATCH"].includes(init.method) && Object.keys(bodyData).length > 0) {
1915
+ init.body = JSON.stringify(bodyData);
1893
1916
  }
1894
1917
  if (options.verbose) {
1895
1918
  console.error(`\u{1F4E4} ${init.method} ${url}`);