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.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}`);