@zauthx402/sdk 0.1.10 → 0.1.14

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.js CHANGED
@@ -4047,6 +4047,14 @@ var ZauthClient = class {
4047
4047
  * Queue an event for batched submission
4048
4048
  */
4049
4049
  queueEvent(event) {
4050
+ const MAX_QUEUE_SIZE = 500;
4051
+ if (this.eventQueue.length >= MAX_QUEUE_SIZE) {
4052
+ this.log("Event queue full, dropping oldest event", { queueSize: this.eventQueue.length });
4053
+ this.eventQueue.shift();
4054
+ }
4055
+ if ("body" in event && event.body && JSON.stringify(event.body).length > 1e4) {
4056
+ event.body = { _truncated: true, _originalSize: JSON.stringify(event.body).length };
4057
+ }
4050
4058
  this.eventQueue.push(event);
4051
4059
  this.log("Event queued", { type: event.type, eventId: event.eventId, queueSize: this.eventQueue.length });
4052
4060
  if (this.eventQueue.length >= this.config.batching.maxBatchSize) {
@@ -4082,9 +4090,13 @@ var ZauthClient = class {
4082
4090
  try {
4083
4091
  await this.submitBatch(events);
4084
4092
  } catch (error) {
4085
- if (this.config.batching.retry) {
4093
+ const errorMsg = error.message || "";
4094
+ const isPayloadTooLarge = errorMsg.includes("413");
4095
+ if (this.config.batching.retry && !isPayloadTooLarge) {
4086
4096
  this.log("Batch failed, re-queuing events", { count: events.length });
4087
4097
  this.eventQueue.unshift(...events);
4098
+ } else if (isPayloadTooLarge) {
4099
+ this.log("Batch payload too large, dropping events", { count: events.length });
4088
4100
  }
4089
4101
  } finally {
4090
4102
  this.isFlushing = false;
@@ -4600,7 +4612,8 @@ function decodePaymentHeader(paymentHeader) {
4600
4612
  if (!payer && parsed.payload?.transaction) {
4601
4613
  payer = extractSolanaFeePayer(parsed.payload.transaction);
4602
4614
  }
4603
- const amount = parsed.payload?.authorization?.value || // x402 V2
4615
+ const amount = parsed.payload?.authorization?.value || // x402 V2 EVM
4616
+ parsed.accepted?.amount || // x402 V2 (accepted payment requirements)
4604
4617
  parsed.amount || parsed.payload?.amount || null;
4605
4618
  let network = parsed.payload?.authorization?.network || // x402 V2 EVM
4606
4619
  parsed.network || parsed.payload?.network || null;
@@ -5062,8 +5075,8 @@ var RefundExecutor = class {
5062
5075
  this.log("Refund executor not enabled");
5063
5076
  return;
5064
5077
  }
5065
- if (!this.config.signer && !this.config.privateKey) {
5066
- this.log("Refund executor requires signer or privateKey");
5078
+ if (!this.config.signer && !this.config.privateKey && !this.config.solanaPrivateKey) {
5079
+ this.log("Refund executor requires signer, privateKey, or solanaPrivateKey");
5067
5080
  return;
5068
5081
  }
5069
5082
  this.log("Starting refund executor (WebSocket mode)", {
@@ -5552,7 +5565,7 @@ function createZauthMiddleware(options) {
5552
5565
  const includePatterns = options.includeRoutes?.map((p) => new RegExp(p)) || [];
5553
5566
  const excludePatterns = options.excludeRoutes?.map((p) => new RegExp(p)) || [];
5554
5567
  let refundExecutor;
5555
- if (config.refund.enabled && (config.refund.signer || config.refund.privateKey)) {
5568
+ if (config.refund.enabled && (config.refund.signer || config.refund.privateKey || config.refund.solanaPrivateKey)) {
5556
5569
  refundExecutor = createRefundExecutor(client, config.refund, config.debug);
5557
5570
  refundExecutor.start();
5558
5571
  if (config.debug) {
@@ -5678,11 +5691,11 @@ function createZauthMiddleware(options) {
5678
5691
  let paymentResponse = reqPaymentInfo || headerPaymentResponse;
5679
5692
  if (facilitatorResponse?.payer) {
5680
5693
  const defaultAmount = options.defaultPaymentAmountUsdc;
5694
+ const decodedAmountUsdc = decodedPayment?.amount ? baseUnitsToUsdc(decodedPayment.amount) : null;
5681
5695
  paymentResponse = {
5682
5696
  transactionHash: facilitatorResponse.transaction || null,
5683
- amountPaid: null,
5684
- // Amount not in facilitator response
5685
- amountPaidUsdc: defaultAmount || null,
5697
+ amountPaid: decodedPayment?.amount || null,
5698
+ amountPaidUsdc: decodedAmountUsdc || defaultAmount || null,
5686
5699
  network: facilitatorResponse.network || "base",
5687
5700
  payTo: null,
5688
5701
  asset: "USDC",