joule-sdk 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/client.js +11 -3
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -43,10 +43,18 @@ class JouleClient {
43
43
  throw new Error(`Compute server error (${initialResponse.status}): ${errorBody?.error?.message || "Unknown error"}`);
44
44
  }
45
45
  // Step 2: Extract payment requirements from 402 response
46
- const errorBody = await initialResponse.json();
47
- const requirements = errorBody.paymentRequirements;
46
+ // Prefer X-Payment header (base64 JSON), fall back to body.paymentRequirements
47
+ const xPaymentHeader = initialResponse.headers.get("X-Payment");
48
+ let requirements;
49
+ if (xPaymentHeader) {
50
+ requirements = JSON.parse(Buffer.from(xPaymentHeader, "base64").toString("utf-8"));
51
+ }
52
+ else {
53
+ const errorBody = await initialResponse.json();
54
+ requirements = errorBody.paymentRequirements;
55
+ }
48
56
  if (!requirements) {
49
- throw new Error("402 response missing paymentRequirements — is this an x402-enabled endpoint?");
57
+ throw new Error("402 response missing payment requirements — is this an x402-enabled endpoint?");
50
58
  }
51
59
  // Step 3: Build and sign Soroban transfer
52
60
  const paymentPayload = await (0, wallet_1.buildSignedPayment)(this.keypair, requirements, this.network, this.rpcUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joule-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Pay for AI inference with JOULE tokens on Stellar — handles x402 payment protocol automatically",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",