@acedatacloud/sdk 2026.718.1 → 2026.722.0

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/index.d.mts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * When the API returns `402 Payment Required`, the transport calls the
5
5
  * configured `PaymentHandler` to produce the extra headers (typically
6
- * `X-Payment`) to attach to the retry. This keeps the SDK free of any
6
+ * `PAYMENT-SIGNATURE`) to attach to the retry. This keeps the SDK free of any
7
7
  * chain-specific signing logic, and lets callers plug in a real x402
8
8
  * implementation such as `@acedatacloud/x402-client`.
9
9
  */
@@ -11,7 +11,9 @@
11
11
  interface PaymentRequirement {
12
12
  scheme: string;
13
13
  network: string;
14
- maxAmountRequired: string;
14
+ amount?: string;
15
+ /** @deprecated Legacy challenge field. */
16
+ maxAmountRequired?: string;
15
17
  maxTimeoutSeconds?: number;
16
18
  resource?: string;
17
19
  description?: string;
@@ -34,7 +36,7 @@ interface PaymentHandlerContext {
34
36
  }
35
37
  /** Result a payment handler must return. */
36
38
  interface PaymentHandlerResult {
37
- /** Extra headers to attach to the retry (must include `X-Payment`). */
39
+ /** Extra headers to attach to the retry (normally `PAYMENT-SIGNATURE`). */
38
40
  headers: Record<string, string>;
39
41
  }
40
42
  /** A callable that signs/settles a payment and returns retry headers. */
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * When the API returns `402 Payment Required`, the transport calls the
5
5
  * configured `PaymentHandler` to produce the extra headers (typically
6
- * `X-Payment`) to attach to the retry. This keeps the SDK free of any
6
+ * `PAYMENT-SIGNATURE`) to attach to the retry. This keeps the SDK free of any
7
7
  * chain-specific signing logic, and lets callers plug in a real x402
8
8
  * implementation such as `@acedatacloud/x402-client`.
9
9
  */
@@ -11,7 +11,9 @@
11
11
  interface PaymentRequirement {
12
12
  scheme: string;
13
13
  network: string;
14
- maxAmountRequired: string;
14
+ amount?: string;
15
+ /** @deprecated Legacy challenge field. */
16
+ maxAmountRequired?: string;
15
17
  maxTimeoutSeconds?: number;
16
18
  resource?: string;
17
19
  description?: string;
@@ -34,7 +36,7 @@ interface PaymentHandlerContext {
34
36
  }
35
37
  /** Result a payment handler must return. */
36
38
  interface PaymentHandlerResult {
37
- /** Extra headers to attach to the retry (must include `X-Payment`). */
39
+ /** Extra headers to attach to the retry (normally `PAYMENT-SIGNATURE`). */
38
40
  headers: Record<string, string>;
39
41
  }
40
42
  /** A callable that signs/settles a payment and returns retry headers. */
package/dist/index.js CHANGED
@@ -123,6 +123,23 @@ var TimeoutError = class extends APIError {
123
123
  };
124
124
 
125
125
  // src/runtime/transport.ts
126
+ function parsePaymentRequired(resp, text) {
127
+ const encoded = resp.headers.get("PAYMENT-REQUIRED");
128
+ if (encoded) {
129
+ try {
130
+ return JSON.parse(atob(encoded));
131
+ } catch {
132
+ throw mapError(402, {
133
+ error: { code: "invalid_402", message: "Invalid PAYMENT-REQUIRED header" }
134
+ });
135
+ }
136
+ }
137
+ try {
138
+ return JSON.parse(text);
139
+ } catch {
140
+ throw mapError(402, { error: { code: "invalid_402", message: text } });
141
+ }
142
+ }
126
143
  var ERROR_CODE_MAP = {
127
144
  invalid_token: AuthenticationError,
128
145
  token_expired: AuthenticationError,
@@ -231,12 +248,7 @@ var Transport = class {
231
248
  clearTimeout(timer);
232
249
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
233
250
  const text = await resp.text();
234
- let body;
235
- try {
236
- body = JSON.parse(text);
237
- } catch {
238
- throw mapError(402, { error: { code: "invalid_402", message: text } });
239
- }
251
+ const body = parsePaymentRequired(resp, text);
240
252
  if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
241
253
  (requirement) => requirement !== null && typeof requirement === "object"
242
254
  )) {
@@ -312,12 +324,7 @@ var Transport = class {
312
324
  }
313
325
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
314
326
  const text = await resp.text();
315
- let body;
316
- try {
317
- body = JSON.parse(text);
318
- } catch {
319
- throw mapError(402, { error: { code: "invalid_402", message: text } });
320
- }
327
+ const body = parsePaymentRequired(resp, text);
321
328
  if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
322
329
  (requirement) => requirement !== null && typeof requirement === "object"
323
330
  )) {