@ar-agents/mercadopago 0.17.2 → 0.18.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.cts CHANGED
@@ -3,6 +3,7 @@ export { L as AutoRecurring, N as CurrencyId, U as FrequencyType, V as Marketpla
3
3
  import { I as IdempotencyCache, S as SubscriptionStateAdapter, A as AuditLogger, a as AuditOperation } from './audit-B9Nhj3PH.cjs';
4
4
  export { b as AuditEntry, c as AuditLogAdapter, d as InMemoryAuditLog, e as InMemoryIdempotencyCache, f as InMemoryOAuthTokenStore, g as InMemoryStateAdapter, O as OAuthTokenRecord, h as OAuthTokenStore, i as SubscriptionStateRecord } from './audit-B9Nhj3PH.cjs';
5
5
  import { ToolSet, Tool } from 'ai';
6
+ import { ArAgentsError } from '@ar-agents/core';
6
7
  import 'zod';
7
8
 
8
9
  /**
@@ -174,12 +175,27 @@ declare class CircuitBreaker {
174
175
  * Base class for any error originating from the Mercado Pago integration. All
175
176
  * specific error types extend this. Carries the MP HTTP status, the parsed
176
177
  * body when available, and the endpoint that failed for debugging.
178
+ *
179
+ * Extends `ArAgentsError` from `@ar-agents/core` so the family contract
180
+ * (code / retryable / context) is uniform across every `@ar-agents/*`
181
+ * integration. Existing public properties (`status`, `endpoint`,
182
+ * `mpResponse`) are preserved on the instance AND mirrored into
183
+ * `context` for callers using the new contract.
184
+ *
185
+ * `code` is derived from the MP error type (e.g. `"mp_auth_failed"`,
186
+ * `"mp_rate_limited"`, `"mp_overloaded"`); the generic surface uses
187
+ * `"mp_api_error"`. `retryable` defaults to true for 5xx, 429, and
188
+ * timeouts; false otherwise.
177
189
  */
178
- declare class MercadoPagoError extends Error {
179
- status: number;
180
- endpoint: string;
181
- mpResponse?: unknown | undefined;
182
- constructor(message: string, status: number, endpoint: string, mpResponse?: unknown | undefined);
190
+
191
+ declare class MercadoPagoError extends ArAgentsError {
192
+ readonly status: number;
193
+ readonly endpoint: string;
194
+ readonly mpResponse?: unknown;
195
+ constructor(message: string, status: number, endpoint: string, mpResponse?: unknown, init?: {
196
+ code?: string;
197
+ retryable?: boolean;
198
+ });
183
199
  }
184
200
  /**
185
201
  * Thrown when the access token is missing, expired, or rejected by MP.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { L as AutoRecurring, N as CurrencyId, U as FrequencyType, V as Marketpla
3
3
  import { I as IdempotencyCache, S as SubscriptionStateAdapter, A as AuditLogger, a as AuditOperation } from './audit-B9Nhj3PH.js';
4
4
  export { b as AuditEntry, c as AuditLogAdapter, d as InMemoryAuditLog, e as InMemoryIdempotencyCache, f as InMemoryOAuthTokenStore, g as InMemoryStateAdapter, O as OAuthTokenRecord, h as OAuthTokenStore, i as SubscriptionStateRecord } from './audit-B9Nhj3PH.js';
5
5
  import { ToolSet, Tool } from 'ai';
6
+ import { ArAgentsError } from '@ar-agents/core';
6
7
  import 'zod';
7
8
 
8
9
  /**
@@ -174,12 +175,27 @@ declare class CircuitBreaker {
174
175
  * Base class for any error originating from the Mercado Pago integration. All
175
176
  * specific error types extend this. Carries the MP HTTP status, the parsed
176
177
  * body when available, and the endpoint that failed for debugging.
178
+ *
179
+ * Extends `ArAgentsError` from `@ar-agents/core` so the family contract
180
+ * (code / retryable / context) is uniform across every `@ar-agents/*`
181
+ * integration. Existing public properties (`status`, `endpoint`,
182
+ * `mpResponse`) are preserved on the instance AND mirrored into
183
+ * `context` for callers using the new contract.
184
+ *
185
+ * `code` is derived from the MP error type (e.g. `"mp_auth_failed"`,
186
+ * `"mp_rate_limited"`, `"mp_overloaded"`); the generic surface uses
187
+ * `"mp_api_error"`. `retryable` defaults to true for 5xx, 429, and
188
+ * timeouts; false otherwise.
177
189
  */
178
- declare class MercadoPagoError extends Error {
179
- status: number;
180
- endpoint: string;
181
- mpResponse?: unknown | undefined;
182
- constructor(message: string, status: number, endpoint: string, mpResponse?: unknown | undefined);
190
+
191
+ declare class MercadoPagoError extends ArAgentsError {
192
+ readonly status: number;
193
+ readonly endpoint: string;
194
+ readonly mpResponse?: unknown;
195
+ constructor(message: string, status: number, endpoint: string, mpResponse?: unknown, init?: {
196
+ code?: string;
197
+ retryable?: boolean;
198
+ });
183
199
  }
184
200
  /**
185
201
  * Thrown when the access token is missing, expired, or rejected by MP.
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { ArAgentsError } from '@ar-agents/core';
1
2
  import { tool } from 'ai';
2
3
  import { z } from 'zod';
3
4
 
@@ -69,19 +70,25 @@ var init_crypto = __esm({
69
70
  encoder = new TextEncoder();
70
71
  }
71
72
  });
72
-
73
- // src/errors.ts
74
- var MercadoPagoError = class extends Error {
75
- constructor(message, status, endpoint, mpResponse) {
76
- super(message);
77
- this.status = status;
78
- this.endpoint = endpoint;
79
- this.mpResponse = mpResponse;
80
- this.name = "MercadoPagoError";
81
- }
73
+ var MercadoPagoError = class extends ArAgentsError {
82
74
  status;
83
75
  endpoint;
84
76
  mpResponse;
77
+ constructor(message, status, endpoint, mpResponse, init = {}) {
78
+ super(message, {
79
+ code: init.code ?? "mp_api_error",
80
+ retryable: init.retryable ?? (status >= 500 || status === 429 || status === 0),
81
+ context: {
82
+ status,
83
+ endpoint,
84
+ ...mpResponse !== void 0 ? { mpResponse } : {}
85
+ }
86
+ });
87
+ this.name = "MercadoPagoError";
88
+ this.status = status;
89
+ this.endpoint = endpoint;
90
+ if (mpResponse !== void 0) this.mpResponse = mpResponse;
91
+ }
85
92
  };
86
93
  var MercadoPagoAuthError = class extends MercadoPagoError {
87
94
  constructor(endpoint, body) {
@@ -89,7 +96,8 @@ var MercadoPagoAuthError = class extends MercadoPagoError {
89
96
  "Mercado Pago rejected the request as unauthorized. Check the access token (TEST- prefix for sandbox, APP_USR- for production).",
90
97
  401,
91
98
  endpoint,
92
- body
99
+ body,
100
+ { code: "mp_auth_failed", retryable: false }
93
101
  );
94
102
  this.name = "MercadoPagoAuthError";
95
103
  }
@@ -159,7 +167,8 @@ var MercadoPagoRateLimitError = class extends MercadoPagoError {
159
167
  `Mercado Pago rate limit hit on ${endpoint}. ${retryAfterSeconds ? `Retry after ${retryAfterSeconds}s.` : "Retry with exponential backoff."}`,
160
168
  429,
161
169
  endpoint,
162
- body
170
+ body,
171
+ { code: "mp_rate_limited", retryable: true }
163
172
  );
164
173
  this.retryAfterSeconds = retryAfterSeconds;
165
174
  this.name = "MercadoPagoRateLimitError";
@@ -171,7 +180,9 @@ var MercadoPagoOverloadedError = class extends MercadoPagoError {
171
180
  super(
172
181
  `Mercado Pago appears overloaded \u2014 returned a non-JSON ${status} response for ${endpoint}. Wait a few seconds and retry.`,
173
182
  status,
174
- endpoint
183
+ endpoint,
184
+ void 0,
185
+ { code: "mp_overloaded", retryable: true }
175
186
  );
176
187
  this.name = "MercadoPagoOverloadedError";
177
188
  }
@@ -181,7 +192,9 @@ var MercadoPagoTimeoutError = class extends MercadoPagoError {
181
192
  super(
182
193
  `Mercado Pago request timed out after ${timeoutMs}ms on ${endpoint}. Increase requestTimeoutMs or check connectivity.`,
183
194
  0,
184
- endpoint
195
+ endpoint,
196
+ void 0,
197
+ { code: "mp_timeout", retryable: true }
185
198
  );
186
199
  this.timeoutMs = timeoutMs;
187
200
  this.name = "MercadoPagoTimeoutError";