@acedatacloud/sdk 2026.718.0 → 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.
@@ -17,6 +17,24 @@ import type {
17
17
  PaymentRequiredBody,
18
18
  } from './payment';
19
19
 
20
+ function parsePaymentRequired(resp: Response, text: string): PaymentRequiredBody {
21
+ const encoded = resp.headers.get('PAYMENT-REQUIRED');
22
+ if (encoded) {
23
+ try {
24
+ return JSON.parse(atob(encoded)) as PaymentRequiredBody;
25
+ } catch {
26
+ throw mapError(402, {
27
+ error: { code: 'invalid_402', message: 'Invalid PAYMENT-REQUIRED header' },
28
+ });
29
+ }
30
+ }
31
+ try {
32
+ return JSON.parse(text) as PaymentRequiredBody;
33
+ } catch {
34
+ throw mapError(402, { error: { code: 'invalid_402', message: text } });
35
+ }
36
+ }
37
+
20
38
  const ERROR_CODE_MAP: Record<string, typeof APIError> = {
21
39
  invalid_token: AuthenticationError,
22
40
  token_expired: AuthenticationError,
@@ -171,12 +189,7 @@ export class Transport {
171
189
 
172
190
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
173
191
  const text = await resp.text();
174
- let body: unknown;
175
- try {
176
- body = JSON.parse(text);
177
- } catch {
178
- throw mapError(402, { error: { code: 'invalid_402', message: text } });
179
- }
192
+ const body = parsePaymentRequired(resp, text);
180
193
  if (
181
194
  !body ||
182
195
  typeof body !== 'object' ||
@@ -267,12 +280,7 @@ export class Transport {
267
280
 
268
281
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
269
282
  const text = await resp.text();
270
- let body: unknown;
271
- try {
272
- body = JSON.parse(text);
273
- } catch {
274
- throw mapError(402, { error: { code: 'invalid_402', message: text } });
275
- }
283
+ const body = parsePaymentRequired(resp, text);
276
284
  if (
277
285
  !body ||
278
286
  typeof body !== 'object' ||